Skip to main content

BERT+ TF Keras For NLP Tasks

说明:本项目处于开发阶段,暂时不可用

简介:以Tensorflow的Keras和Tensorflow hub的Bert预训练模型开发NLP的各种任务。

项目特点

  • 下载稳定,较为典型的测试数据,附带详细介绍
  • 数据接口封装,减少数据的处理工作
  • 模型采用tf.keras完成,方便快捷不失灵活
  • 方便的保存模型和部署

环境

  • Tensorflow:1.13.1
  • Tensorflow-hub

TODO List

句子向量化

  • 但是存在一个重复加载计算图导致速度变慢的问题,体验不佳,后续将改进。 已解决,解决方法是直接使用BERT的分词器,不从hub重新加载,撒花!
  • 性能测试
  • Batch输入

文本分类

  • 二分类任务

已完成。数据量不大的情况下可以不使用微调,否则参数量增大可能会过拟合。

  • 多分类任务 BERT的多分类任务和二分类类似,只需要修改标签,然后sigmod换softmax,损失函数也换成多分类交叉熵即可。目前没有稳定的外链数据,所以没写example。
  • 多标签任务

序列标注

  • NER

开发中

阅读理解

  • 斯坦福SQUAD类似的中文检索式阅读理解

未完成

模型保存和部署

  • h5转saved_model。
  • 最好的方式是可以使用tf.keras.experimental.export_saved_model导出模型,然后直接使用TF serving部署。

TF Data输入

  • 多输入的TF Data写法
  • GPU利用率的比较

其他计划

  • Tensorflow hub加载本地路径
  • Windows测试

其他说明

  • 为什么用tf.keras而不是keras tf.keras成为TF2.0的主要模式,由TF团队开发,支持更多TF的特性包括tf.data以及tf serving,TF2.0出了之后项目会迁移到TF2.0,而keras已经较长时间没有重大更新了,所以tf.keras是更好的选择。
  • 由于网络原因,无法下载Tensorflow hub的BERT模型 这里有一份百度云的,链接, 提取码:4pcq,大小为364.1M,linux下载解压后拷贝到/tmp/,完成后的路径为/tmp/tfhub_modules

参考项目

Metadata

Release files for bert-text 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bert-text 0.1.0
File Size Uploaded
bert-text-0.1.0.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bert-text 0.1.0
File Interpreter ABI Platform
bert_text-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.8 kB

Release files / bert-text-0.1.0.tar.gz

Download URL bert-text-0.1.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a294fc2f10974459006e5827bff9a122d0767ce66d36aa72789125d73342bd85
BLAKE2b-256 checksum
How to use checksums
cb170be97f9d254414f516c7b97a15542aa6c8be89964c69d9ba560147f80034
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.5

Release files / bert_text-0.1.0-py3-none-any.whl

Download URL bert_text-0.1.0-py3-none-any.whl
Size 2.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bab374cf3fd03cc58ec7f7f8330dbbce7f823c71f400656b6c5c0df683bc5fc
BLAKE2b-256 checksum
How to use checksums
0e90271a67bfa4940c5a7d763a5e2091076d476da6dcd2af89c38847b5933f5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page