一个易于使用的开放源代码库,用于高级深度学习和自然语言处理
tamnun的Python项目详细描述
tamnun毫升
tamnun
是一个python框架,用于机器和深度学习算法和方法,特别是在自然语言处理和转移学习领域。tamnun
的目的是提供一个易于使用的接口,以便基于最新的sota方法构建强大的模型。
有关tamnun
的更多信息,请阅读the introduction to TamnunML on Medium。
入门
tamnun
依赖于其他一些机器学习和深度学习框架,如pytorch
、keras
和其他框架。要安装tamnun
及其所有依赖项,请运行:
$ git clone https://github.com/hiredscorelabs/tamnun-ml
$ cd tamnun-ml
$ python setup.py install
或者使用pypi:
pip install tamnun
跳入并尝试一个示例:
$ cd examples
$ python finetune_bert.py
或者看看Jupyer笔记本here。
伯特
bert表示来自transformers的双向编码器表示,transformers是由google训练并在其{a5}中引入的语言模型。
在这里,我们使用优秀的PyTorch-Pretrained-BERT库并对其进行包装,以提供一个易于使用的scikit-learn接口,便于进行bert微调。目前,tamnun
bert分类器支持二类和多类分类。要对特定任务的bert进行微调:
fromtamnun.bertimportBertClassifier,BertVectorizerfromsklearn.pipelineimportmake_pipelineclf=make_pipeline(BertVectorizer(),BertClassifier(num_of_classes=2)).fit(train_X,train_y)predicted=clf.predict(test_X)
有关完整的代码示例,请参见this notebook。
使用一条线安装(几乎)任何pytorch模块
您可以使用TorchEstimator
对象来容纳任何pytorch
模块,只要一行:
fromtorchimportnnfromtamnun.coreimportTorchEstimatormodule=nn.Linear(128,2)clf=TorchEstimator(module,task_type='classification').fit(train_X,train_y)
请参阅this file,以获取在MNIST(手写数字分类)数据集上拟合nn.Linear
模块的完整示例。
蒸馏器转移学习
这个模块将一个非常大(像bert)的模型提取为一个更小的模型。灵感来源于这个paper。
fromtamnun.bertimportBertClassifier,BertVectorizerfromtamnun.transferimportDistillerbert_clf=make_pipeline(BertVectorizer(do_truncate=True,max_len=3),BertClassifier(num_of_classes=2))distilled_clf=make_pipeline(CountVectorizer(ngram_range=(1,3)),LinearRegression())distiller=Distiller(teacher_model=bert_clf,teacher_predict_func=bert_clf.decision_function,student_model=distilled_clf).fit(train_texts,train_y,unlabeled_X=unlabeled_texts)predicted_logits=distiller.transform(test_texts)
完整的伯特蒸馏示例见this笔记本。
支架
获取帮助
您可以在Github Issues
许可证
apache许可证2.0(与tensorflow相同)