๐ Bespin Question Answering Model
This project is a fine - tuned question - answering model based on BERT, aiming to provide high - quality question - answering services using the AIHub dataset.
๐ Quick Start
You can try out the model through the following demo link:
โจ Features
- Model Type: Fine - tuned BERT - based question - answering model.
- Training Data: AIHub machine reading comprehension dataset.
๐ฆ Installation
This section is skipped as no installation steps are provided in the original document.
๐ป Usage Examples
Basic Usage
import torch
from transformers import AutoModelForQuestionAnswering, AutoTokenizer
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
def predict_answer(qa_text_pair):
encodings = tokenizer(context, question,
max_length=512,
truncation=True,
padding="max_length",
return_token_type_ids=False,
return_offsets_mapping=True
)
encodings = {key: torch.tensor([val]).to(device) for key, val in encodings.items()}
pred = model(encodings["input_ids"], attention_mask=encodings["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 = encodings["input_ids"][0][token_start_index: token_end_index + 1]
answer_text = tokenizer.decode(pred_ids)
answer_start_offset = int(encodings['offset_mapping'][0][token_start_index][0][0])
answer_end_offset = int(encodings['offset_mapping'][0][token_end_index][0][1])
answer_offset = (answer_start_offset, answer_end_offset)
return {'answer_text':answer_text, 'answer_offset':answer_offset}
HUGGINGFACE_MODEL_PATH = "bespin-global/klue-bert-base-aihub-mrc"
tokenizer = AutoTokenizer.from_pretrained(HUGGINGFACE_MODEL_PATH)
model = AutoModelForQuestionAnswering.from_pretrained(HUGGINGFACE_MODEL_PATH).to(device)
context = '''์ ํ M2(Apple M2)๋ ์ ํ์ด ์ค๊ณํ ์ค์ ์ฒ๋ฆฌ ์ฅ์น(CPU)์ ๊ทธ๋ํฝ ์ฒ๋ฆฌ ์ฅ์น(GPU)์ ARM ๊ธฐ๋ฐ ์์คํ
์ด๋ค.
์ธํ
์ฝ์ด(Intel Core)์์ ๋งฅํจํ ์ ์ปดํจํฐ์ฉ์ผ๋ก ์ค๊ณ๋ 2์ธ๋ ARM ์ํคํ
์ฒ์ด๋ค. ์ ํ์ 2022๋
6์ 6์ผ WWDC์์ ๋งฅ๋ถ ์์ด, 13์ธ์น ๋งฅ๋ถ ํ๋ก์ ํจ๊ป M2๋ฅผ ๋ฐํํ๋ค.
์ ํ M1์ ํ์์์ด๋ค. M2๋ TSMC์ 'ํฅ์๋ 5๋๋
ธ๋ฏธํฐ ๊ธฐ์ ' N5P ๊ณต์ ์ผ๋ก ๋ง๋ค์ด์ก์ผ๋ฉฐ, ์ด์ ์ธ๋ M1๋ณด๋ค 25% ์ฆ๊ฐํ 200์ต๊ฐ์ ํธ๋์ง์คํฐ๋ฅผ ํฌํจํ๊ณ ์์ผ๋ฉฐ, ์ต๋ 24๊ธฐ๊ฐ๋ฐ์ดํธ์ RAM๊ณผ 2ํ
๋ผ๋ฐ์ดํธ์ ์ ์ฅ๊ณต๊ฐ์ผ๋ก ๊ตฌ์ฑํ ์ ์๋ค.
8๊ฐ์ CPU ์ฝ์ด(์ฑ๋ฅ 4๊ฐ, ํจ์จ์ฑ 4๊ฐ)์ ์ต๋ 10๊ฐ์ GPU ์ฝ์ด๋ฅผ ๊ฐ์ง๊ณ ์๋ค. M2๋ ๋ํ ๋ฉ๋ชจ๋ฆฌ ๋์ญํญ์ 100 GB/s๋ก ์ฆ๊ฐ์ํจ๋ค.
์ ํ์ ๊ธฐ์กด M1 ๋๋น CPU๊ฐ ์ต๋ 18%, GPU๊ฐ ์ต๋ 35% ํฅ์๋๋ค๊ณ ์ฃผ์ฅํ๊ณ ์์ผ๋ฉฐ,[1] ๋ธ๋ฃธ๋ฒ๊ทธํต์ ์ M2๋งฅ์ค์ CPU ์ฝ์ด 12๊ฐ์ GPU ์ฝ์ด 38๊ฐ๊ฐ ํฌํจ๋ ๊ฒ์ด๋ผ๊ณ ๋ณด๋ํ๋ค.'''
question = "m2๊ฐ m1์ ๋นํด ์ผ๋ง๋ ์ข์์ก์ด?"
qa_text_pair = {'context':context, 'question':question}
result = predict_answer(qa_text_pair)
print('Answer Text: ', result['answer_text'])
print('Answer Offset: ', result['answer_offset'])
๐ Documentation
Finetuning
{
"epochs": 4,
"batch_size":8,
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
"optimizer_params": {
"lr": 3e-05
},
"weight_decay": 0.01
}
๐ง Technical Details
This section is skipped as there is no detailed technical implementation information in the original document.
๐ License
This project is licensed under the CC - BY - NC - 4.0 license.
๐ Citing & Authors
You can find more information about the authors here:
Jaehyeong at Bespin Global