Skip to content

Commit

Permalink
Merge pull request #2243 from stw2/master
Browse files Browse the repository at this point in the history
added object that downloads the files for corpus with  Swahili language
  • Loading branch information
alanakbik committed Apr 21, 2021
2 parents 31154b2 + 17a9a8e commit 429765b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions flair/datasets/sequence_labeling.py
Expand Up @@ -1927,6 +1927,55 @@ def __init__(
**corpusargs,
)

class SWAHILI_NER(ColumnCorpus):
def __init__(
self,
base_path: Union[str, Path] = None,
tag_to_bioes: str = "ner",
in_memory: bool = True,
**corpusargs,
):
"""
Initialize the Swahili corpus available on:
https://github.com/masakhane-io/masakhane-ner/tree/main/data/swa.
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
path = "https://raw.githubusercontent.com/masakhane-io/masakhane-ner/main/data/swa/"

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

super(SWAHILI_NER, self).__init__(
data_folder,
columns,
tag_to_bioes=tag_to_bioes,
encoding="utf-8",
in_memory=in_memory,
**corpusargs,
)

class NER_BASQUE(ColumnCorpus):
def __init__(
Expand Down

0 comments on commit 429765b

Please sign in to comment.