简体   繁体   English

' '.join() 在 NLP 谷歌 API 中解析命名实体识别时出错

[英]Error with ' '.join() parsing txt for named entity recognition in NLP google API

I'm having a rough time in trying to construct a dataset for Named Entity Recognition in Google NLP API, via this script provided by Google input_helper_v2.py我在尝试通过 Google input_helper_v2.py提供的脚本为 Google NLP API 中的命名实体识别构建数据集时遇到了困难

The problem comes with the function _DownloadGcsFile , as it throws this error:问题出现在函数_DownloadGcsFile 上,因为它会引发此错误:

gsutil_cp_cmd = ' '.join(['gsutil', 'cp', gcs_file, local_filename])
TypeError: sequence item 2: expected str instance, bytes found

I've tried to put b' '.join(['gsutil', 'cp', gcs_file, local_filename]) , but it yields to similar problems.我试图把b' '.join(['gsutil', 'cp', gcs_file, local_filename]) ,但它产生了类似的问题。

In searching for information, I noticed that it could be the script being developed in python 2.7 what is causing this.在搜索信息时,我注意到可能是在 python 2.7 中开发的脚本导致了这种情况。

I'll appreciate any help, as I'm a complete beginner.我将不胜感激,因为我是一个完整的初学者。 Thank you so much.非常感谢。

Well it means that gcs_file has type bytes .嗯,这意味着 gcs_file 的类型为bytes So you need to make it a string ( str ) type.因此,您需要将其设为字符串 ( str ) 类型。 For example:例如:

gsutil_cp_cmd = ' '.join(['gsutil', 'cp', gcs_file.decode('utf-8'), local_filename])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM