OpenICL
1.0.0
概要•インストール•論文•例•ドキュメント•引用
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 (String-Typeテンプレートなど)の詳細については、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 }
}