Skip to content
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

Added NER Support for Yoruba #2230

Merged
merged 4 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flair/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .sequence_labeling import NER_BASQUE
from .sequence_labeling import NER_FINNISH
from .sequence_labeling import NER_SWEDISH
from .sequence_labeling import NER_YORUBA
from .sequence_labeling import STACKOVERFLOW_NER
from .sequence_labeling import SEMEVAL2010
from .sequence_labeling import SEMEVAL2017
Expand Down
48 changes: 48 additions & 0 deletions flair/datasets/sequence_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,54 @@ def __init__(
**corpusargs,
)

class NER_YORUBA(ColumnCorpus):
def __init__(
self,
base_path: Union[str, Path] = None,
tag_to_bioes: str = "ner",
in_memory: bool = True,
**corpusargs,
):
"""
Initialize the Yoruba corpus for NER available on:
https://github.com/masakhane-io/masakhane-ner/tree/main/data/yor
The first time you call this constructor it will automatically download the dataset.
:param base_path: Default is None, meaning that corpus gets auto-downloaded and loaded. You can override this
to point to a different folder but typically this should not be necessary.
:param tag_to_bioes: NER by default, need not be changed, but you could also select 'pos' to predict
POS tags instead
:param in_memory: If True, keeps dataset in memory giving speedups in training.
:param document_as_sequence: If True, all sentences of a document are read into a single Sentence object
"""
if type(base_path) == str:
base_path: Path = Path(base_path)

# column format
columns = {0: "text", 1: "ner"}

# this dataset name
dataset_name = self.__class__.__name__.lower()

# default dataset folder is the cache root
if not base_path:
base_path = Path(flair.cache_root) / "datasets"
data_folder = base_path / dataset_name

# download data if necessary
model_path = "https://github.com/masakhane-io/masakhane-ner/main/data/yor/"

cached_path(f"{model_path}test.txt", Path("datasets") / dataset_name)
cached_path(f"{model_path}train.txt", Path("datasets") / dataset_name)
cached_path(f"{model_path}dev.txt", Path("datasets") / dataset_name)

super(NER_YORUBA, self).__init__(
data_folder,
columns,
tag_to_bioes=tag_to_bioes,
in_memory=in_memory,
**corpusargs,
)


class KINYARWANDA_NER(ColumnCorpus):
def __init__(
Expand Down