Tinjauan Umum • Instalasi • Kertas • Contoh • Dokumen • Kutipan
OpenICL menyediakan antarmuka yang mudah untuk pembelajaran dalam konteks, dengan banyak metode pengambilan canggih dan inferensi yang dibangun untuk memfasilitasi perbandingan sistematis LMS dan prototipe penelitian cepat. Pengguna dapat dengan mudah memasukkan metode pengambilan dan inferensi yang berbeda, serta instruksi cepat yang berbeda ke dalam alur kerja mereka.
Catatan: OpenICL membutuhkan Python 3.8+
Menggunakan pip
pip install openicl
Instalasi untuk pengembangan lokal:
git clone https://github.com/Shark-NLP/OpenICL
cd OpenICL
pip install -e .
Contoh berikut menunjukkan kepada Anda cara melakukan ICL pada dataset klasifikasi sentimen. Lebih banyak contoh dan tutorial dapat ditemukan di contoh
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>' ) Placeholder </E> dan </text> akan diganti dengan contoh in-context dan input pengujian, masing-masing. Untuk informasi lebih rinci tentang PromptTemplate (seperti Template Jenis String), silakan lihat 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 )Di sini kami menggunakan metode topk populer untuk membangun retriever.
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 )(memperbarui ...)
Dokumentasi OpenICL
Jika Anda menemukan repositori ini bermanfaat, jangan ragu untuk mengutip kertas kami:
@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 }
}