-
Notifications
You must be signed in to change notification settings - Fork 40
DAGE-107: Add a script to download bbc news dataset and support batch indexing in docker-services #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
DAGE-107: Add a script to download bbc news dataset and support batch indexing in docker-services #250
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
rre-tools/configs/embedding_model_evaluator/embedding_model_evaluator_config.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| ## Extract BBC News Dataset | ||
|
|
||
| [The script](extract_bbc_news_dataset.py) downloads and processes BBC News articles from the [RealTimeData/bbc_news_alltime](https://huggingface.co/datasets/RealTimeData/bbc_news_alltime) | ||
| dataset using HuggingFace. | ||
|
|
||
| It filters, deduplicates, truncates long content, adds UUIDs, and saves the results to a JSON file. | ||
|
|
||
| ``` | ||
| python extract_bbc_news_dataset.py --filename output.json | ||
| ``` | ||
| Arguments: | ||
|
|
||
| `--filename`: Output JSON filename (default: dataset.json) |
94 changes: 94 additions & 0 deletions
94
rre-tools/docker-services/scripts/extract_bbc_news_dataset.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import argparse | ||
| import json | ||
| import uuid | ||
|
|
||
| from datasets import load_dataset | ||
| from tqdm import tqdm | ||
|
|
||
| CONTENT_MAX_LEN = 1000 | ||
| DATASET_SIZE = 100000 | ||
|
|
||
|
|
||
| def truncate_content(txt: str) -> str: | ||
| if len(txt) > CONTENT_MAX_LEN: | ||
| truncated: str = txt[:CONTENT_MAX_LEN] | ||
|
|
||
| next_dot = txt.find('.', CONTENT_MAX_LEN) | ||
| if next_dot != -1 and next_dot - CONTENT_MAX_LEN < 200: | ||
| truncated = txt[:next_dot + 1] | ||
|
|
||
| return truncated | ||
| return txt | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
| parser = argparse.ArgumentParser(description="Extract BBC News Dataset") | ||
| parser.add_argument('--filename', type=str, default='dataset.json', help='Output filename') | ||
| args = parser.parse_args() | ||
|
|
||
| months = ['2025-06', '2025-05', '2025-04', '2025-03', '2025-02', '2025-01', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about something like
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
| '2024-12', '2024-11', '2024-10', '2024-09', '2024-08', '2024-07', '2024-06', '2024-05', '2024-04', | ||
| '2024-03', '2024-02', '2024-01', | ||
| '2023-12', '2023-11', '2023-10', '2023-09', '2023-08', '2023-07', '2023-06', '2023-05', '2023-04', | ||
| '2023-03', '2023-02', '2023-01', | ||
| '2022-12', '2022-11', '2022-10', '2022-09', '2022-08', '2022-07', '2022-06', '2022-05', '2022-04', | ||
| '2022-03', '2022-02', '2022-01', | ||
| '2021-12', '2021-11', '2021-10', '2021-09', '2021-08', '2021-07', '2021-06', '2021-05', '2021-04', | ||
| '2021-03', '2021-02', '2021-01', | ||
| '2020-12', '2020-11', '2020-10', '2020-09', '2020-08', '2020-07', '2020-06', '2020-05', '2020-04', | ||
| '2020-03', '2020-02', '2020-01', | ||
| '2019-12', '2019-11', '2019-10', '2019-09', '2019-08', '2019-07', '2019-06', '2019-05', '2019-04', | ||
| '2019-03', '2019-02', '2019-01', | ||
| '2018-12', '2018-11', '2018-10', '2018-09', '2018-08', '2018-07', '2018-06', '2018-05', '2018-04', | ||
| '2018-03', '2018-02', '2018-01', | ||
| '2017-12', '2017-11', '2017-10', '2017-09', '2017-08', '2017-07', '2017-06', '2017-05', '2017-04', | ||
| '2017-03', '2017-02', '2017-01' | ||
| ] | ||
| all_results = [] | ||
| seen_links = set() | ||
|
|
||
| for month in tqdm(months): | ||
| ds = load_dataset("RealTimeData/bbc_news_alltime", month) | ||
|
|
||
| for elem in ds['train']: | ||
| # skip if section=empty/None | ||
| if not elem.get("section") or elem.get("section") is None: | ||
| continue | ||
|
|
||
| if not elem.get("title"): | ||
| continue | ||
|
|
||
| # skip duplicates based on the web link | ||
| link = elem.get("link") | ||
| if not link or link in seen_links: | ||
| continue | ||
| seen_links.add(link) | ||
|
|
||
| # truncate long content | ||
| content = elem.get("content", "") | ||
| if not content: | ||
| continue | ||
| text = truncate_content(content) | ||
| elem["content"] = text | ||
|
|
||
| elem["id"] = str(uuid.uuid4()) | ||
|
|
||
| # id first shows up in the json file | ||
| id_val = elem.pop("id") | ||
| new_elem = {"id": id_val, **elem} | ||
|
|
||
| all_results.append(new_elem) | ||
| if len(all_results) == DATASET_SIZE: | ||
| break | ||
| if len(all_results) == DATASET_SIZE: | ||
| break | ||
| print(len(all_results)) | ||
|
|
||
| # for solr + vespa | ||
| with open(args.filename, "w", encoding="utf-8") as f: | ||
| json.dump(all_results, f, ensure_ascii=False, indent=4) | ||
| # for opensearch + elasticsearch | ||
| # with open("dataset.jsonl", "w", encoding="utf-8") as f: | ||
| # for obj in all_results: | ||
| # f.write(json.dumps(obj, ensure_ascii=False) + "\n") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| artificial intelligence | ||
| President Trump | ||
| vacation | ||
| covid-19 | ||
| Ukraine war | ||
| bitcoin crypto | ||
| tech layoffs | ||
| job market | ||
| Gaza strip | ||
| Cannes film festival |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, if we find a dot after the max len can become 1200, right?
Maybe we can check the last dot backward, so we keep the content len under
CONTENT_MAX_LENUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, its max is 1200, because the reason is i noticed there is a long sentence which sometimes reaches at least 1100 and in case if we remove the sentence which reaches the last sentence after reaching 1000 chars and the content becomes around 800. That's why I set upper bound to 1200. But on average I saw about 1100 chars per content. Anyways, it is changeable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me is fine like it is right now, indeed I approved. So feel free to keep it like this. The only thing is that when I read the code,
CONTENT_MAX_LENis set to 1000 but the "actual one" is 1200 (i.e., I often end up with more than 1k chars), since we are addressing the problem of finding the first dot after 1000. But this is just a little thing. I don't want to block anythingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the code for readability