【问题标题】:Translation with multi-lingual BERT model使用多语言 BERT 模型进行翻译
【发布时间】:2022-12-13 23:47:19
【问题描述】:

我想使用多语言 BERT 翻译我的数据框。 我已经复制了这段代码,但我想使用我自己的数据框代替text

from transformers import BertTokenizer, TFBertModel
tokenizer = BertTokenizer.from_pretrained('bert-base-multilingual-cased')
model = TFBertModel.from_pretrained("bert-base-multilingual-cased")
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)

但是,我在使用它时遇到一些错误,如下所示。

df  =pd.read_csv("/content/drive/text.csv")
encoded_input = tokenizer(df, return_tensors='tf')

错误

ValueError: text input must of type `str` (single example), `List[str]` (batch or single pretokenized example) or `List[List[str]]` (batch of pretokenized examples).

我的数据框看起来像这样

0    There is XXXX increased opacity within the rig...
1    There is XXXX increased opacity within the rig...
2    There is XXXX increased opacity within the rig...
3    Interstitial markings are diffusely prominent ...
4    Interstitial markings are diffusely prominent ...
Name: findings, dtype: object

【问题讨论】:

    标签: pandas nlp bert-language-model


    【解决方案1】:

    第一个是使用细绳分词器. 第二个你试图标记整个数据框,不是字符串。

    【讨论】:

    • 如何为整个数据框做?
    • 您可以使用数据集的一小部分样本来编辑问题吗?
    • 您可以在字符串列表中转换所需的列,然后使用分词器。 df['desired_column'].values.tolist()
    • 在执行df['desired_column'].values.tolist() 后,我得到同样的错误ValueError: text input must of type str (single example), List[str] (batch or single pretokenized example) ValueError: text input must of type str (single example), List[str] (batch or single pretokenized example)。我也更新了我的问题。
    • 你能做一个循环来标记每个吗?
    猜你喜欢
    • 2012-10-21
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    • 2020-08-14
    • 2015-04-03
    • 1970-01-01
    • 2021-11-02
    相关资源
    最近更新 更多