ภาพรวม•การติดตั้ง•กระดาษ•ตัวอย่าง•เอกสาร•การอ้างอิง
OpenICL ให้อินเทอร์เฟซที่ง่ายสำหรับการเรียนรู้ในบริบทด้วยวิธีการดึงข้อมูลและการอนุมานที่ล้ำสมัยจำนวนมากที่สร้างขึ้นเพื่ออำนวยความสะดวกในการเปรียบเทียบ LMS อย่างเป็นระบบและต้นแบบการวิจัยที่รวดเร็ว ผู้ใช้สามารถรวมวิธีการดึงและการอนุมานที่แตกต่างกันได้อย่างง่ายดายรวมถึงคำแนะนำที่แตกต่างกันในเวิร์กโฟลว์ของพวกเขา
หมายเหตุ: OpenICL ต้องการ Python 3.8+
ใช้ PIP
pip install openicl
การติดตั้งเพื่อการพัฒนาในท้องถิ่น:
git clone https://github.com/Shark-NLP/OpenICL
cd OpenICL
pip install -e .
ตัวอย่างต่อไปนี้แสดงวิธีการดำเนินการ ICL ในชุดข้อมูลการจำแนกความเชื่อมั่น ตัวอย่างและบทช่วยสอนเพิ่มเติมสามารถดูได้จากตัวอย่าง
from datasets import load_dataset
from openicl import DatasetReader
# Loading dataset from huggingface
dataset = load_dataset ( 'gpt3mix/sst2' )
# Define a DatasetReader, with specified column names where input and output are stored.
data = DatasetReader ( dataset , input_columns = [ 'text' ], output_column = 'label' ) from openicl import PromptTemplate
tp_dict = {
0 : "</E>Positive Movie Review: </text>" ,
1 : "</E>Negative Movie Review: </text>"
}
template = PromptTemplate ( tp_dict , { 'text' : '</text>' }, ice_token = '</E>' ) ตัวยึด </E> และ </text> จะถูกแทนที่ด้วยตัวอย่างในบริบทและการทดสอบอินพุตตามลำดับ สำหรับข้อมูลรายละเอียดเพิ่มเติมเกี่ยวกับ PromptTemplate (เช่นเทมเพลตประเภทสตริง) โปรดดู Tutorial1
from openicl import TopkRetriever
# Define a retriever using the previous `DataLoader`.
# `ice_num` stands for the number of data in in-context examples.
retriever = TopkRetriever ( data , ice_num = 8 )ที่นี่เราใช้วิธี Topk ยอดนิยมเพื่อสร้างรีทรีฟเวอร์
from openicl import PPLInferencer
inferencer = PPLInferencer ( model_name = 'distilgpt2' ) from openicl import AccEvaluator
# the inferencer requires retriever to collect in-context examples, as well as a template to wrap up these examples.
predictions = inferencer . inference ( retriever , ice_template = template )
# compute accuracy for the prediction
score = AccEvaluator (). score ( predictions = predictions , references = data . references )
print ( score )(อัปเดต ... )
เอกสาร OpenICL
หากคุณพบว่าพื้นที่เก็บข้อมูลนี้มีประโยชน์อย่าลังเลที่จะอ้างถึงกระดาษของเรา:
@article { wu2023openicl ,
title = { OpenICL: An Open-Source Framework for In-context Learning } ,
author = { Zhenyu Wu, Yaoxiang Wang, Jiacheng Ye, Jiangtao Feng, Jingjing Xu, Yu Qiao, Zhiyong Wu } ,
journal = { arXiv preprint arXiv:2303.02913 } ,
year = { 2023 }
}