Skip to content

Commit

Permalink
Merge pull request #2234 from HallerPatrick/master
Browse files Browse the repository at this point in the history
Added NEW support for the Hausa language
  • Loading branch information
alanakbik authored Apr 19, 2021
2 parents 1fa14e4 + 4b09258 commit 2ed8d09
Show file tree
Hide file tree
Showing 2 changed files with 49 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 @@ -22,6 +22,7 @@
from .sequence_labeling import DANE
from .sequence_labeling import EUROPARL_NER_GERMAN
from .sequence_labeling import GERMEVAL_14
from .sequence_labeling import HAUSA_NER
from .sequence_labeling import INSPEC
from .sequence_labeling import JAPANESE_NER
from .sequence_labeling import KINYARWANDA_NER
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 @@ -1697,6 +1697,54 @@ def __init__(
)


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

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


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

0 comments on commit 2ed8d09

Please sign in to comment.