Skip to content

Commit

Permalink
Merge pull request #2214 from lukasvoege/luo-ner
Browse files Browse the repository at this point in the history
Support for Luo language dataset (NER) added
  • Loading branch information
alanakbik authored Apr 16, 2021
2 parents e4e78c7 + b946b4a commit e0c5fec
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions flair/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .sequence_labeling import JAPANESE_NER
from .sequence_labeling import KINYARWANDA_NER
from .sequence_labeling import LER_GERMAN
from .sequence_labeling import LUO_NER
from .sequence_labeling import MIT_MOVIE_NER_SIMPLE
from .sequence_labeling import MIT_MOVIE_NER_COMPLEX
from .sequence_labeling import MIT_RESTAURANT_NER
Expand Down
47 changes: 47 additions & 0 deletions flair/datasets/sequence_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,53 @@ def __init__(
)


class LUO_NER(ColumnCorpus):
def __init__(
self,
base_path: Union[str, Path] = None,
tag_to_bioes: str = "ner",
in_memory: bool = True,
**corpusargs,
):
"""
Initialize the NER Luo language corpus available on https://github.com/masakhane-io/masakhane-ner/tree/main/data/luo.
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
ner_luo_path = "https://raw.githubusercontent.com/masakhane-io/masakhane-ner/main/data/luo/"
cached_path(f"{ner_luo_path}dev.txt", Path("datasets") / dataset_name)
cached_path(f"{ner_luo_path}test.txt", Path("datasets") / dataset_name)
cached_path(f"{ner_luo_path}train.txt", Path("datasets") / dataset_name)

super(LUO_NER, self).__init__(
data_folder,
columns,
tag_to_bioes=tag_to_bioes,
encoding="latin-1",
in_memory=in_memory,
**corpusargs,
)

class MIT_MOVIE_NER_SIMPLE(ColumnCorpus):
def __init__(
self,
Expand Down

0 comments on commit e0c5fec

Please sign in to comment.