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

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第三方库


热门话题
datetime如何使用JodaTime在Java中设置时间属性   java固定算法的性能时间   java如何从JMenu中获取所选项以更改文本区域的文本颜色?   java配置单元UDF传递数组<string>作为参数   javaapachebeam和BigQuery   java与PrintWriter之间的差异。printf和PrintWriter。格式方法   继承如何处理按Java版本更改的导入,以及在多个版本上编译   xml java。lang.noClassDefFoundant生成错误   java如何使用包含映射的JSON发送POST请求?   java如何在任何应用程序的JAR文件中绑定MySql数据库?   Java脚本解释器   sslhttpclientjava。网SocketException:未实现未连接的socket   java如何为Android应用程序创建类似于Cron作业的东西   java JButton+radiobox+复选框   java内存管理将文件写入内存   java这是计算对象实例的有效方法吗?   用于死锁情况的java代码?   JavaSpring容器作为新实体插入,而不是存储在表中