Bert-as-service: What does non-empty mean?

Created on 12 Dec 2018  路  3Comments  路  Source: hanxiao/bert-as-service

Prerequisites

Please fill in by replacing [ ] with [x].

System information

Some of this information can be collected via this script.

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
  • TensorFlow installed from pip3:
  • TensorFlow version 1.11.9:
  • Python version: 3.6.3
  • bert-as-service version: 1.5.0
  • GPU model and memory None:
  • CPU model and memory:

Description

Please replace YOUR_SERVER_ARGS and YOUR_CLIENT_ARGS accordingly. You can also write your own description for reproducing the issue.

I'm using this command to start the server:

bert-serving-start -model_dir PATH  -num_worker=4

and calling the server via:

bc = BertClient()
bc.encode()

Then this issue shows up:

I'm giving list (about 135k sentences, it's a list of strings) as an argument to bc.encode. However, the system answer is AttributeError: "texts" must be "List[str]" and non-empty!

I replace all the occurences of '', ' ' and ' ' and so on in my list for a 'empty' string. However, it turned to be unsufficient.
What is considered to be "empty"? And may be there is a possibility of printing this "empty" sentence in except-branch?

Thank you in advance!

will do

Most helpful comment

Why not return np.zeros whenever input is empty?

All 3 comments

The current version behaves as follows:

for k in ([], [''], ['', ''], ['', []], ['\n', '\r\n'], ['', 's', 'ss'], ['s', 'ss'], ['', 2, 'ss'], [2, 'ss']):
    print('%s\t%s' % (BertClient._is_valid_input(k), k))
False   []
False   ['']
False   ['', '']
False   ['', []]
False   ['\n', '\r\n']
False   ['', 's', 'ss']
True    ['s', 'ss']
False   ['', 2, 'ss']
False   [2, 'ss']

But you are right, would be better to raise an error on the empty case. Mark it as enhancement and will fix it

fyi, this issue is fixed and available in 1.5.1, please do

pip install -U bert-serving-server bert-serving-client

Why not return np.zeros whenever input is empty?

Was this page helpful?
0 / 5 - 0 ratings