klue-bert-base-mrc / README.md
changyeop2's picture
add readme
9660cb4
|
raw
history blame
1.53 kB
metadata
datasets:
  - KLUE-MRC
license: cc-by-sa-4.0

bert-base for QA

NOTE: You can try the model through the Ainize DEMO, and you can call the api through the Ainize API.

Overview

Language model: klue/bert-base
Language: Korean
Downstream-task: Extractive QA
Training data: KLUE-MRC
Eval data: KLUE-MRC
Code: See Ainize Workspace

Usage

In Transformers

from transformers import AutoModelForQuestionAnswering, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("./mrc-bert-base")
model = AutoModelForQuestionAnswering.from_pretrained("./mrc-bert-base")

context = "your context"
question = "your question"

encodings = tokenizer(context, question, max_length=512, truncation=True,
                      padding="max_length", return_token_type_ids=False)

input_ids = encodings["input_ids"]
attention_mask = encodings["attention_mask"]

pred = model(input_ids, attention_mask=attention_mask)

start_logits, end_logits = pred.start_logits, pred.end_logits

token_start_index, token_end_index = start_logits.argmax(dim=-1), end_logits.argmax(dim=-1)

pred_ids = input_ids[0][token_start_index: token_end_index + 1]

prediction = tokenizer.decode(pred_ids)

About us

Teachable NLP - Train NLP models with your own text without writing any code
Ainize - Deploy ML project using free gpu