首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >利用BERT开发答疑系统

利用BERT开发答疑系统
EN

Stack Overflow用户
提问于 2020-07-27 08:48:01
回答 1查看 202关注 0票数 0

我目前正在开发一个问答系统(印度尼西亚语的),我的论文使用了BERT。数据集和提出的问题都是用印度尼西亚文写的。

问题是,我还不清楚如何逐步开发伯特的问答系统。

根据我在阅读了许多研究期刊和论文后得出的结论,这个过程可能是这样的:

model

  • Testing
  1. 准备主数据集
  2. 负载预处理数据
  3. 使用列车前数据(以便生成“精调”模型)
  4. 集群(向system)
  5. Evaluation

提出问题)来训练主数据集。

我想问的是:

  • ,这些步骤正确吗?或者如果step(s)?
  • Also,提供的默认预处理数据是英文的,而我的主要数据集是印度尼西亚语,那么如何创建自己的印度尼西亚培训前数据呢?
  • 它真的需要在BERT

中执行数据/模型聚类吗?

我感谢任何有帮助的回答。先谢谢你。

EN

回答 1

Stack Overflow用户

发布于 2021-07-24 16:43:27

我想看看Huggingface的问题&回答例子。那至少是个好的开始。

代码语言:javascript
复制
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
import torch

tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
model = AutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")

text = r"""
 Transformers (formerly known as pytorch-transformers and pytorch-pretrained-bert) provides general-purpose
architectures (BERT, GPT-2, RoBERTa, XLM, DistilBert, XLNet…) for Natural Language Understanding (NLU) and Natural
Language Generation (NLG) with over 32+ pretrained models in 100+ languages and deep interoperability between
TensorFlow 2.0 and PyTorch.
"""

questions = [
    "How many pretrained models are available in Transformers?",
    "What does Transformers provide?",
    "Transformers provides interoperability between which frameworks?",
]

for question in questions:
    inputs = tokenizer.encode_plus(question, text, add_special_tokens=True, return_tensors="pt")
    input_ids = inputs["input_ids"].tolist()[0]

    text_tokens = tokenizer.convert_ids_to_tokens(input_ids)
    answer_start_scores, answer_end_scores = model(**inputs)

    answer_start = torch.argmax(
        answer_start_scores
    )  # Get the most likely beginning of answer with the argmax of the score
    answer_end = torch.argmax(answer_end_scores) + 1  # Get the most likely end of answer with the argmax of the score

    answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(input_ids[answer_start:answer_end]))

    print(f"Question: {question}")
    print(f"Answer: {answer}\n")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63111754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档