Обзор • Установка • Бумага • Примеры • Документы • Цитирование
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 (например, шаблоне строкового типа), см. Урок1.
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 }
}