Skip to content

Commit

Permalink
added AutoTask
Browse files Browse the repository at this point in the history
  • Loading branch information
Damien Sileo committed Jun 30, 2023
1 parent aa7edca commit 358f6f6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/tasknet/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,24 @@ def compute_metrics(self, eval_preds):
result=self._explode(result)
meta = {"name": self.name, "size": len(decoded_preds), "index": self.index}

return {**result,**meta}
return {**result,**meta}


def AutoTask(dataset, **kwargs):
if type(dataset)==str:
try:
import tasksource
except:
raise ImportError('To use this feature, use a valid tasksource id and pip install tasksource')
try:
dataset = tasksource.load_task(dataset)
except:
raise ValueError('pick an id from https://github.com/sileod/tasksource/blob/main/tasks.md or write your own preprocessing')
features=dataset['train'].features
if 'sentence1' in features:
return Classification(dataset, **kwargs)
if 'choice' in str(features):
return MultipleChoice(dataset, **kwargs)
if 'tokens' in features:
return TokenClassification(dataset,**kwargs)

0 comments on commit 358f6f6

Please sign in to comment.