语言: 韩语
标签:
- bert
- mrc
数据集:
- aihub
许可协议: cc-by-nc-4.0
演示
微调
{
"epochs": 4,
"batch_size":8,
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
"optimizer_params": {
"lr": 3e-05
},
"weight_decay: 0.01
}
使用方式
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)是苹果设计的基于ARM架构的中央处理器(CPU)和图形处理器(GPU)系统。
这是为Macintosh电脑设计的第二代ARM架构,取代了英特尔酷睿(Intel Core)。苹果在2022年6月6日的WWDC上发布了M2,同时推出的还有MacBook Air和13英寸MacBook Pro。
它是苹果M1的后续产品。M2采用台积电的"增强型5纳米技术"N5P工艺制造,包含200亿个晶体管,比前代M1增加了25%,最高可配置24GB内存和2TB存储空间。
拥有8个CPU核心(4个性能核心+4个能效核心)和最多10个GPU核心。M2还将内存带宽提升至100GB/s。
苹果声称相比M1,CPU性能提升最高达18%,GPU性能提升最高达35%。[1]彭博社报道称M2 Max将包含12个CPU核心和38个GPU核心。'''
question = "M2相比M1提升了多少?"
qa_text_pair = {'context':context, 'question':question}
result = predict_answer(qa_text_pair)
print('答案文本: ', result['answer_text'])
print('答案偏移量: ', result['answer_offset'])
引用与作者
Jaehyeong 来自 Bespin Global