Skip to main content

A bert sentence encoding tool

Project description

This is a bert sentence encoding tool.

Install

pip install --index-url https://pypi.python.org/simple/ bert-sent-encoding==0.2.0

or

git clone ssh://git@gitlab.leihuo.netease.com:32200/shaojianzhi/bert-sent-encoding.git
cd bert-sent-encoding
python setup.py install

Use

from bert_sent_encoding import bert_sent_encoding # 1st line
bse = bert_sent_encoding(model_path='bert_sent_encoding/model/chinese_L-12_H-768_A-12', seq_length=64, batch_size=8) # 2nd line
vector = bse.get_vector('你吃饭了吗', word_vector=False, layer=-1)   # 3rd line 1. get vector of string
vectors = bse.get_vector(['你吃饭了吗', '已经吃了呀'], word_vector=False, layer=-1)  # 4th line 2. get vector list of strings
bse.write_txt2vector(input_file, output_file, word_vector=False, layer=-1)   # 5th line 3. get and write vectors of strings

for 2nd line:

bse = bert_sent_encoding(model_path='bert_sent_encoding/model/chinese_L-12_H-768_A-12', seq_length=64, batch_size=8)
*model_path is required, seq_length and batch_size are optional

for 3rd, 4th and 5th lines

vector = bse.get_vector('你吃饭了吗', word_vector=False, layer=-1)   # 3rd line 1. get vector of string
vectors = bse.get_vector(['你吃饭了吗', '已经吃了呀'], word_vector=False, layer=-1)  # 4th line 2. get vector list of strings
bse.write_txt2vector(input_file, output_file, word_vector=False, layer=-1)   # 5th line 3. get and write vectors of strings
*word_vector and layer are optional*

for 5th line:

bse.write_txt2vector(input_file, output_file)   # 3. get and write vectors of strings

path of input_file and output_file are defined by user and below is content of input_file:

the first line text
the second line text
...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bert_sent_encoding-0.2.0.tar.gz (60.3 kB view details)

Uploaded Source

Built Distribution

bert_sent_encoding-0.2.0-py3-none-any.whl (76.6 kB view details)

Uploaded Python 3

File details

Details for the file bert_sent_encoding-0.2.0.tar.gz.

File metadata

  • Download URL: bert_sent_encoding-0.2.0.tar.gz
  • Upload date:
  • Size: 60.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for bert_sent_encoding-0.2.0.tar.gz
Algorithm Hash digest
SHA256 949a2e34ba20350b4c9bd41061bba257ca2fdd58cfe7fa1fda9677da53e95118
MD5 4e8fc3ba017ca0438261b871dd9ca7b4
BLAKE2b-256 b2aed6371487cace22298d568d954ef067bd1b9fb018d805e19a6d4a0950d0d4

See more details on using hashes here.

File details

Details for the file bert_sent_encoding-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: bert_sent_encoding-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 76.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for bert_sent_encoding-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a41678d67298bc41cc9ba80b9faab85081a1226a95bce425763af50ec1cd6372
MD5 7ae28ad197bdbc8a57e2f524d855fa11
BLAKE2b-256 71932811b15dcfdc17fc8f7cbfc43a73f2a907db62971a2f1ec26408b4f34946

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page