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的更多详细信息(例如字符串类型模板),请参见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 }
}