Skip to main content

DeepSE

Python package PyPI version Python

DeepSE: 面向生产环境的Sentence Embedding!

目录

  1. 安装
  2. 实现的模型

安装

克隆仓库:

git clone https://github.com/luozhouyang/deepse.git

或者从pypi安装:

pip install -U deepse

实现的模型

目前支持的模型如下:

  • 原始的BERT和RoBERTa
  • SimCSE
    • Unsupervised SimCSE
    • Supervised SimCSE
    • Supervised SimCSE (with hard negative)

BERT和RoBERTa

TODO: 补充文档

SimCSE

对于不同的版本,训练数据的格式稍有不同,但是都是普通文本文件,每一行都是一个JSON格式的训练样本。

对于Unsupervised SimCSE,每个样本都需要含有sequence字段。举例如下:

{"sequence": "我很讨厌自然语言处理"}
{"sequence": "我对自然语言处理很感兴趣"}

对于Supervised SimCSE,每个样本都需要包含sequence和positive_sequence字段。举例如下:

{"sequence": "我很讨厌自然语言处理", "positive_sequence": "我不喜欢自然语言处理"}
{"sequence": "我对自然语言处理很感兴趣", "positive_sequence": "我想了解自然语言处理"}

对于Supervised SimCSE with hard negative,每个样本都需要包含sequence、positive_sequence和negative_sequence字段。如果positive_sequence字段为空,则会自动使用sequence作为自己的positive_sequence。举例如下:

{"sequence": "我很讨厌自然语言处理", "positive_sequence": "我不喜欢自然语言处理", "negative_sequence": "我想了解自然语言处理"}
{"sequence": "我对自然语言处理很感兴趣", "positive_sequence": "我想了解自然语言处理", "negative_sequence": "我很讨厌自然语言处理"}

然后,使用以下命令即可训练:

export PRETRAINED_MODEL_PATH=/path/to/your/pretrained/bert/dir 
nohup python run_simcse.py >> log/run_simcse.log 2>&1 &
tail -f log/run_simcse.log

参数可以到run_simcse.py直接修改。

模型会同时保存成Checkpoint格式和SavedModel格式,后者你可以直接用tensorflow/serving部署在生产环境。

Metadata

Release files for deepse 0.0.4

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

Source distribution (sdist)

Source distribution for deepse 0.0.4
File Size Uploaded Provenance Actions
deepse-0.0.4.tar.gz 14.4 kB Without provenance Details for deepse-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deepse 0.0.4
File Interpreter ABI Platform Actions
deepse-0.0.4-py3-none-any.whl Python 3 none any Details for deepse-0.0.4-py3-none-any.whl

Total release size: 30.0 kB

Release files / deepse-0.0.4.tar.gz

Download URL deepse-0.0.4.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
176a96b380c84d5c0e9610c92af3fce792ad75cfa99f18f986294edba23abc52
BLAKE2b-256 checksum
How to use checksums
1353e789949e1fce1ea97cca8d3aefe8cd9312bc466ac84ada0f176b1b46198f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release files / deepse-0.0.4-py3-none-any.whl

Download URL deepse-0.0.4-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1436b18bee5c45beb27834f3b76876a06386f83579579704dcb680f5393c9106
BLAKE2b-256 checksum
How to use checksums
21081155ee9d117b67a1d61f5dba876d6f1c92568004aaf30d8720b8f2f7d9be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Security for deepse 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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