-
Notifications
You must be signed in to change notification settings - Fork 45
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
Adding the libre textbooks #149
Open
hssn-20
wants to merge
23
commits into
OpenBioML:main
Choose a base branch
from
hssn-20:add-libre-textbooks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
70a9dd1
initial commit
hssn-20 c4b61fd
Merge branch 'OpenBioML:main' into add-libre-textbooks
hssn-20 6876820
Add files via upload
hssn-20 26b4488
Update transform.py
hssn-20 5de34a7
Update transform.py
hssn-20 c87307a
Libre-textbook web crawler
hssn-20 0bd8b97
version 1
hssn-20 579cc79
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 41fd816
fixing linting issues
hssn-20 41b5dfc
Update transform.py
hssn-20 9c68bf9
Merge branch 'OpenBioML:main' into add-libre-textbooks
hssn-20 bfcdb4c
Add files via upload
hssn-20 8050d7e
Add files via upload
hssn-20 f17e326
Delete lines_to_remove.jsonl
hssn-20 85f161e
Delete top_sentances.ods
hssn-20 706442d
Update transform.py
hssn-20 af2982c
Merge branch 'OpenBioML:main' into add-libre-textbooks
hssn-20 78ff8f7
Merge branch 'OpenBioML:main' into add-libre-textbooks
hssn-20 acd40c3
Update data/libre_textbooks/transform.py
kjappelbaum 12f854f
Update data/libre_textbooks/meta.yaml
kjappelbaum 2e0e0fd
Update data/libre_textbooks/transform.py
kjappelbaum 2ba93b0
Update data/libre_textbooks/transform.py
kjappelbaum b34267c
Update data/libre_textbooks/meta.yaml
kjappelbaum 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 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,30 @@ | ||
--- | ||
name: libre_textbooks | ||
description: A dataset of scraped articles from libre textbooks | ||
targets: | ||
- id: html | ||
description: A scraped page from libre textbooks | ||
units: | ||
type: text | ||
names: | ||
- natural language article | ||
pubchem_aids: [] | ||
uris: [] | ||
identifiers: | ||
- id: url | ||
type: string | ||
description: url of the page the content is scraped from | ||
- id: text_length | ||
type: int | ||
description: text character count | ||
license: CC BY 4.0 | ||
links: | ||
- name: Libre Textbooks | ||
url: https://chem.libretexts.org/Bookshelves | ||
description: '' | ||
- name: Hugging Face dataset upload | ||
url: https://huggingface.co/datasets/Hack90/libre_chem_textbooks | ||
description: Hugging Face dataset uploaded to HF account | ||
benchmarks: [] | ||
num_points: 3740 | ||
bibtex: [] |
This file contains 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,76 @@ | ||||||
from datasets import load_dataset | ||||||
import pandas as pd | ||||||
import yaml | ||||||
|
||||||
|
||||||
LINES_TO_REMOVE = "/workspaces/chemnlp/data/libre_textbooks/lines_to_remove.jsonl" | ||||||
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. This is not used below. Are those lines already removed on the HF dataset upload? |
||||||
RAW_DATASET = "Hack90/libre_chem_textbooks" | ||||||
|
||||||
|
||||||
META_YAML_PATH = "./data/libre_textbooks/meta.yaml" | ||||||
META_TEMPLATE = { | ||||||
"name": "libre_textbooks", # unique identifier, we will also use this for directory names | ||||||
"description": "A dataset of scraped articles from libre textbooks", | ||||||
"targets": [ | ||||||
{ | ||||||
"id": "html", # name of the column in a tabular dataset | ||||||
"description": "A scraped page from libre textbooks", | ||||||
"units": None, # units of the values in this column (leave empty if unitless) | ||||||
"type": "string", # can be "categorical", "ordinal", "continuous", "string" | ||||||
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.
Suggested change
|
||||||
"names": [ # names for the property (to sample from for building the prompts) | ||||||
"natural language article", | ||||||
], | ||||||
"pubchem_aids": [], | ||||||
"uris": [], | ||||||
}, | ||||||
], | ||||||
"identifiers": [ | ||||||
{ | ||||||
"id": "url", # column name | ||||||
"type": "Other", # can be "SMILES", "SELFIES", "IUPAC", "OTHER" | ||||||
"description": "url of the page the content is scraped from", | ||||||
}, | ||||||
], | ||||||
"license": "CC BY 4.0", # license under which the original dataset was published | ||||||
"links": [ # list of relevant links (original dataset, other uses, etc.) | ||||||
{ | ||||||
"name": "Libre Textbooks", | ||||||
"url": "https://chem.libretexts.org/Bookshelves", | ||||||
"description": "", | ||||||
}, | ||||||
{ | ||||||
"name": "Hugging Face dataset upload", | ||||||
"url": "https://huggingface.co/datasets/Hack90/libre_chem_textbooks", | ||||||
"description": "Hugging Face dataset uploaded to HF account", # Hopefully will move this | ||||||
# to the openbioml space | ||||||
}, | ||||||
], | ||||||
"benchmarks": [], | ||||||
"num_points": 3740, # number of datapoints in this dataset | ||||||
"bibtex": [ | ||||||
# noqa | ||||||
], | ||||||
} | ||||||
|
||||||
|
||||||
def get_raw_data(raw_dataset: str = RAW_DATASET) -> pd.DataFrame: | ||||||
"""Load the raw dataset into a pandas dataframe""" | ||||||
dataset = load_dataset(raw_dataset) | ||||||
df_raw = pd.DataFrame(dataset["train"].to_pandas()) | ||||||
return df_raw | ||||||
|
||||||
|
||||||
def create_meta_yaml(num_points: int): | ||||||
"""Create meta configuration file for the dataset""" | ||||||
# create meta yaml | ||||||
META_TEMPLATE["num_points"] = num_points | ||||||
with open(META_YAML_PATH, "w+") as f: | ||||||
yaml.dump(META_TEMPLATE, f, sort_keys=False) | ||||||
print(f"Finished processing libre_textbooks {META_TEMPLATE['name']} dataset!") | ||||||
|
||||||
|
||||||
if __name__ == "__main__": | ||||||
num_samples = 0 | ||||||
raw_df = get_raw_data() | ||||||
num_samples += len(raw_df) | ||||||
create_meta_yaml(num_samples) |
Oops, something went wrong.
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.