一个易于使用的开放源代码库,用于高级深度学习和自然语言处理

tamnun的Python项目详细描述


tamnun毫升

PyPI pyversionsCircleCI

tamnun是一个python框架,用于机器和深度学习算法和方法,特别是在自然语言处理和转移学习领域。tamnun的目的是提供一个易于使用的接口,以便基于最新的sota方法构建强大的模型。

有关tamnun的更多信息,请阅读the introduction to TamnunML on Medium

入门

tamnun依赖于其他一些机器学习和深度学习框架,如pytorchkeras和其他框架。要安装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微调。目前,tamnunbert分类器支持二类和多类分类。要对特定任务的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相同)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java无法启动应用程序:JNLP错误   java根据用户输入在PreparedStatement中使用setTime()或setNull()   java EJB与同步   java以object为键通过hashmap进行搜索   java中的模10^9+7   针对包含其他对象的对象的java OOP最佳实践   如何将字符串作为HTML代码从Java文件读取到JSP页面?   java我的POM怎么了?“解析表达式..检测到递归表达式循环”   用于Hbase的Mapreduce的java NoSuchMethodError   JAVAlang.SecurityException:权限拒绝:启动意图{act=安卓.Intent.action.MAIN cat=[安卓.Intent.category.LAUNCHER]   数组初始化谜语Java   通过arraylist搜索时的java句柄关联