-
Notifications
You must be signed in to change notification settings - Fork 8
Add dataset #1
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
base: master
Are you sure you want to change the base?
Add dataset #1
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| from typing import Dict, Type, Union | ||
|
|
||
| from s2s.dset._arith import ArithDset | ||
| from s2s.dset._eng2chi import Eng2ChiDset | ||
| from s2s.dset._base import BaseDset | ||
|
|
||
| Dset = Union[ | ||
| ArithDset, | ||
| Eng2ChiDset, | ||
| ] | ||
|
|
||
| DSET_OPTS: Dict[str, Type[Dset]] = { | ||
| ArithDset.dset_name: ArithDset, | ||
| Eng2ChiDset.dset_name: Eng2ChiDset | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import os | ||
|
|
||
| from typing import Sequence | ||
|
|
||
| import pandas as pd | ||
| from sklearn.metrics import accuracy_score | ||
|
|
||
| from s2s.dset._base import BaseDset | ||
| from s2s.path import DATA_PATH | ||
|
|
||
| class Eng2ChiDset(BaseDset): | ||
| dset_name = 'eng2chi' | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| df = pd.read_csv(os.path.join(DATA_PATH, 'eng2chi.csv')) | ||
| self.src.extend( | ||
| df['src'].apply(str).apply(self.__class__.preprocess).to_list() | ||
| ) | ||
| self.tgt.extend( | ||
| df['tgt'].apply(str).apply(self.__class__.preprocess).to_list() | ||
| ) | ||
|
|
||
| @staticmethod | ||
|
Owner
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. For translation, one should use evaluation metrics other than exact match (i.e., generate words must "be the same word" and "in the same order" of target sequence , which is used by |
||
| def eval(tgt: str, pred: str) -> float: | ||
| return float(tgt == pred) | ||
|
|
||
| @staticmethod | ||
| def batch_eval( | ||
| batch_tgt: Sequence[str], | ||
| batch_pred: Sequence[str], | ||
| ) -> float: | ||
| return accuracy_score(batch_tgt, batch_pred) | ||
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.
Add docstring for
Eng2ChiDsetclass, including reference of the source of the dataset.