Whitespace & minor bugfix to
- As much as possible, following the existing task hierarchy structure.
- When inheriting, be sure to write and call load_data.
- Set all text data as an attribute, task.sentences (List[List[str]])
-- Each task's val_metric should be name_metric, where metric is returned by get_metrics()
+- Each task's val_metric should be name_metric, where metric is returned by
+get_metrics(): e.g. if task.val_metric = task_name + "_accuracy", then
+task.get_metrics() should return {"accuracy": accuracy_val, ... }
'''
import copy
import collections
@@ -14,9 +16,10 @@ import math
import logging as log
import json
import numpy as np
-from typing import Iterable, Sequence, Any, Type
+from typing import Iterable, Sequence, List, Dict, Any, Type
-from allennlp.training.metrics import CategoricalAccuracy, F1Measure, Average
+from allennlp.training.metrics import CategoricalAccuracy, \
+ BooleanAccuracy, F1Measure, Average
from allennlp.data.token_indexers import SingleIdTokenIndexer
from .allennlp_mods.correlation import Correlation
@@ -30,7 +33,7 @@ from . import utils
from .utils import load_tsv, process_sentence, truncate
REGISTRY = {} # Do not edit manually!
-def register_task(name, rel_path, kw=None):
+def register_task(name, rel_path, **kw):
'''Decorator to register a task.
Use this instead of adding to NAME2INFO in preprocess.py
@@ -153,8 +156,8 @@ class Task():
''' Process split text into a list of AllenNLP Instances. '''
raise NotImplementedError
- def get_metrics(self, reset=False):
- '''Get metrics specific to the task'''
+ def get_metrics(self, reset: bool=False) -> Dict:
+ ''' Get metrics specific to the task. '''
raise NotImplementedError
