diff --git a/ulmfit/__main__.py b/ulmfit/__main__.py index f17c040..43e1f1f 100644 --- a/ulmfit/__main__.py +++ b/ulmfit/__main__.py @@ -12,8 +12,8 @@ class Experiment: def load(self, model_path): return ulmfit.ULMFiT().load_(Path(model_path)) - def download(self): - raise NotImplementedError("implement model fetching") + def from_pretrained(self): + return ulmfit.ULMFiT.from_pretrained if __name__ == '__main__': fire.Fire(Experiment()) \ No newline at end of file diff --git a/ulmfit/training.py b/ulmfit/training.py index ca56ffe..79b501b 100644 --- a/ulmfit/training.py +++ b/ulmfit/training.py @@ -462,3 +462,15 @@ class ULMFiT: {self.finetune_lm}, {self.classifier}, )""") + + def from_pretrained_(self, name, repo="PiotrCzapla/multifit-models"): + name = name.rstrip(".tgz") # incase someone put's tgz name the name + url = f"https://github.com/{repo}/releases/download/{name}/{name}.tgz" + path = untar_data(url.rstrip(".tgz"), data=False) # untar_data adds .tgz + return self.load_(path) + + @classmethod + def from_pretrained(cls, name): + #TODO: Detect name and load configuration + from . import configurations + return configurations.multifit_paper_version().from_pretrained_(name)