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 Template)에 대한 자세한 내용은 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 }
}