-
Notifications
You must be signed in to change notification settings - Fork 24
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
build: apply a typical project boilerplate of BigScience repo #56
Merged
jaketae
merged 2 commits into
bigscience-workshop:main
from
tianjianjiang:build-apply_project_boilerplate
Aug 19, 2021
Merged
Changes from all commits
Commits
Show all changes
2 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 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,23 @@ | ||
name: Code quality | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install -U pip | ||
python -m pip install -r requirements-dev.txt | ||
- name: Check code quality | ||
run: make quality |
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,25 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install -U pip | ||
python -m pip install . | ||
python -m pip install -r requirements-dev.txt | ||
- name: Test | ||
run: python -m pytest tests |
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,12 @@ | ||
.PHONY: quality style | ||
|
||
check_dirs := . | ||
|
||
quality: # Check that source code meets quality standards | ||
black --check $(check_dirs) | ||
isort --check-only $(check_dirs) | ||
flake8 $(check_dirs) --max-line-length 119 | ||
|
||
style: # Format source code automatically | ||
black $(check_dirs) | ||
isort $(check_dirs) |
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
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
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
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
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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
# Module for any additional processing required for the TyDi QA dataset | ||
# HuggingFace dataset link: https://huggingface.co/datasets/tydiqa | ||
from typing import Dict | ||
|
||
from datasets import load_dataset | ||
from jinja2 import Template | ||
from torch.utils.data import Dataset | ||
from datasets import load_dataset | ||
from tqdm import tqdm | ||
|
||
from evaluation.tasks.auto_task import AutoTask | ||
|
||
|
||
TEMPLATE = Template( | ||
""" | ||
{%- set _blank=["passage", "text", "text snippet", "context"]|random -%} | ||
|
@@ -21,7 +20,7 @@ | |
{{"\n"}}{{context}} | ||
{%- endif -%} | ||
{{"\n"}}Answer: | ||
""" | ||
""" # noqa W291 | ||
Comment on lines
22
to
+23
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. |
||
) | ||
|
||
|
||
|
@@ -31,23 +30,23 @@ def __init__(self, tokenizer, target_langs): | |
assert tokenizer.pad_token == tokenizer.eos_token | ||
tydiqa = load_dataset("tydiqa", "secondary_task", split="validation") | ||
self.items = [] | ||
|
||
for sample in tydiqa: | ||
lang = sample["id"].split("-")[0] | ||
if lang in target_langs: | ||
# Filter out samples in languages that are not used during training | ||
prompt = TEMPLATE.render( | ||
id = sample["id"], | ||
context = sample["context"], | ||
question = sample["question"], | ||
id=sample["id"], | ||
context=sample["context"], | ||
question=sample["question"], | ||
) | ||
prompt = prompt.strip() # Remove trailing white space and newline | ||
|
||
# Tokenize and construct this sample | ||
inputs = tokenizer( | ||
prompt, | ||
padding=True, | ||
return_tensors='pt', | ||
return_tensors="pt", | ||
) | ||
self.items.append( | ||
{ | ||
|
@@ -56,27 +55,27 @@ def __init__(self, tokenizer, target_langs): | |
"input_ids": inputs["input_ids"], | ||
"attention_mask": inputs["attention_mask"], | ||
"input_len": inputs["attention_mask"].shape[1], | ||
"target_answer": [ans.lower() for ans in sample["answers"]['text']], | ||
"target_answer": [ans.lower() for ans in sample["answers"]["text"]], | ||
} | ||
) | ||
|
||
def __len__(self): | ||
return len(self.items) | ||
|
||
def __getitem__(self, index): | ||
return self.items[index] | ||
|
||
|
||
class TydiqaSecondaryTask(AutoTask): | ||
@staticmethod | ||
def get_display_name() -> str: | ||
return 'tydiqa_secondary' | ||
return "tydiqa_secondary" | ||
|
||
def evaluate(self) -> None: | ||
dataset = TyDiQADataset(self.tokenizer, target_langs=self.task_config["target_langs"]) | ||
|
||
substring_matches = 0 | ||
for sample in tqdm(dataset, desc=f'Evaluating {self.get_display_name()}'): | ||
for sample in tqdm(dataset, desc=f"Evaluating {self.get_display_name()}"): | ||
output = self.model.generate( | ||
input_ids=sample["input_ids"].to(self.device), | ||
attention_mask=sample["attention_mask"].to(self.device), | ||
|
@@ -91,6 +90,4 @@ def evaluate(self) -> None: | |
substring_match = any([target_answer in predicted_answer.lower() for target_answer in target_answers]) | ||
substring_matches += substring_match | ||
|
||
self.metrics = { | ||
"substring_matches": substring_matches / len(dataset) * 100 | ||
} | ||
self.metrics = {"substring_matches": substring_matches / len(dataset) * 100} |
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
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.
Although the trailing whitespace after
Answer:
is understandable,load_dataset()
may still remove it with tokenizer, cf. https://github.com/bigscience-workshop/evaluation/pull/56/files#r690616263The
noqa W291
is just to makeflake8
happy. If the trailing whitespace can be removed from the template, then no need to havenoqa
here.