Instructions to use Soeon/2025_NIKL_RAG_ISNLP1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Soeon/2025_NIKL_RAG_ISNLP1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Soeon/2025_NIKL_RAG_ISNLP1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Soeon/2025_NIKL_RAG_ISNLP1") model = AutoModelForCausalLM.from_pretrained("Soeon/2025_NIKL_RAG_ISNLP1", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Soeon/2025_NIKL_RAG_ISNLP1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Soeon/2025_NIKL_RAG_ISNLP1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Soeon/2025_NIKL_RAG_ISNLP1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Soeon/2025_NIKL_RAG_ISNLP1
- SGLang
How to use Soeon/2025_NIKL_RAG_ISNLP1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Soeon/2025_NIKL_RAG_ISNLP1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Soeon/2025_NIKL_RAG_ISNLP1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Soeon/2025_NIKL_RAG_ISNLP1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Soeon/2025_NIKL_RAG_ISNLP1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Soeon/2025_NIKL_RAG_ISNLP1 with Docker Model Runner:
docker model run hf.co/Soeon/2025_NIKL_RAG_ISNLP1
Download data.py from Soeon/2025_NIKL_RAG_ISNLP1: direct link, hf CLI and curl.
- Browser
- Download file 6.55 kB
-
https://huggingface.co/Soeon/2025_NIKL_RAG_ISNLP1/resolve/main/data.py
- Command line
-
hf download hf://Soeon/2025_NIKL_RAG_ISNLP1/data.py
-
curl -L -o data.py https://huggingface.co/Soeon/2025_NIKL_RAG_ISNLP1/resolve/main/data.py
6.55 kB
| import json | |
| import torch | |
| from torch.utils.data import Dataset | |
| PROMPT = '''You are a helpful AI assistant. Please answer the user's questions kindly. \ | |
| 당신은 한국의 전통 문화와 역사, 문법, 사회, 과학기술 등 다양한 분야에 대해 잘 알고 있는 유능한 AI 어시스턴트 입니다. 사용자의 질문에 대해 친절하게 답변해주세요. \ | |
| 단, 동일한 문장을 절대 반복하지 마시오.''' | |
| DEFAULT_CORRECTION_PROMPT = ( | |
| "[지침]과 [예시]를 참고하여, [질문]을 잘 읽고 [답변]을 생성하시오. 문제를 그대로 출력하지 마시오.\n" | |
| "[지침]\n" | |
| "주어진 문장이 올바른지 판단하고, 틀린 경우 올바르게 교정하여 \"~가 옳다.\" 형태로 답변하고, 그 이유를 설명하시오.\n\n" | |
| "[예시]\n" | |
| "[질문]\n다음 문장에서 어문 규범에 부합하지 않는 부분을 찾아 고치고, 그 이유를 설명하세요.\n\"오늘은 퍼즐 마추기를 해 볼 거예요.\"\n" | |
| "[답변]\n\"오늘은 퍼즐 맞추기를 해 볼 거예요.\"가 옳다. '제자리에 맞게 붙이다, 주문하다, 똑바르게 하다, 비교하다' 등의 뜻이 있는 말은 '마추다'가 아닌 '맞추다'로 적는다." | |
| ) | |
| DEFAULT_SELECTION_PROMPT = ( | |
| "[지침]과 [예시]를 참고하여, [질문]을 잘 읽고 [답변]을 생성하시오. 문제를 그대로 출력하지 마시오.\n" | |
| "[지침]\n" | |
| "주어진 보기들 중에서 가장 적절한 것을 선택하여 \"~가 옳다.\" 형태로 답변하고, 그 이유를 설명하시오.\n\n" | |
| "[예시]\n" | |
| "[질문]\n\"나는 그를 본 적이 있음을 {기억해냈다/기억해 냈다}.\" 가운데 올바른 것을 선택하고, 그 이유를 설명하세요.\n" | |
| "[답변]\n\"나는 그를 본 적이 있음을 기억해 냈다.\"가 옳다. '기억해 냈다'는 '기억하-+-아+냈다'의 구성이다. 이처럼 '본용언+-아/-어+보조 용언' 구성인 경우 본용언과 보조 용언을 붙여 쓰는 것이 허용되지만, 이러한 구성을 갖더라도 앞말이 3음절 이상의 합성어나 파생어라면 보조 용언을 붙여 쓰는 것이 허용되지 않는다. '기억하다'는 '기억'과 '-하다'가 결합한 파생어이며 '기억해'는 3음절이다. 따라서 '기억해'와 '냈다'는 띄어 써야 한다." | |
| ) | |
| class CustomDataset(Dataset): | |
| def __init__(self, fname, tokenizer, prompt=PROMPT, correction_prompt=DEFAULT_CORRECTION_PROMPT, selection_prompt=DEFAULT_SELECTION_PROMPT): | |
| IGNORE_INDEX=-100 | |
| self.inp = [] | |
| self.label = [] | |
| self.prompt = prompt if prompt != "None" else PROMPT | |
| self.correction_prompt = correction_prompt if correction_prompt != "None" else DEFAULT_CORRECTION_PROMPT | |
| self.selection_prompt = selection_prompt if selection_prompt != "None" else DEFAULT_SELECTION_PROMPT | |
| print(f'\n\n[DBG] prompt: {self.prompt}') | |
| print(f'\n\n[DBG] correction_prompt: {self.correction_prompt}') | |
| print(f'\n\n[DBG] selection_prompt: {self.selection_prompt}') | |
| with open(fname, "r") as f: | |
| data = json.load(f) | |
| def make_chat(inp): | |
| # question type별 instruction 정의 | |
| type_instructions = { | |
| "교정형": self.correction_prompt, | |
| "선택형": self.selection_prompt | |
| } | |
| # question type에 따른 instruction 선택 | |
| instruction = type_instructions.get(inp['question_type'], "") | |
| # 기타 정보 생성 (question과 question_type 제외) | |
| other_info = {k: v for k, v in inp.items() if k not in ['question', 'question_type']} | |
| # 기타 정보가 있는 경우에만 추가 | |
| chat_parts = [instruction] | |
| if other_info: | |
| info_list = ["[기타 정보]"] | |
| for key, value in other_info.items(): | |
| info_list.append(f"- {key}: {value}") | |
| chat_parts.append("\n".join(info_list)) | |
| # 질문 추가 | |
| chat_parts.append(f"[질문]\n{inp['question']}") | |
| # 최종 프롬프트 생성 | |
| chat = "\n\n".join(chat_parts) | |
| # print(f'[DBG] chat: {chat}') | |
| return chat | |
| for example in data: | |
| user_prompt = make_chat(example["input"]) | |
| message = [ | |
| {"role": "system", "content": self.prompt}, | |
| {"role": "user", "content": user_prompt}, | |
| ] | |
| if False: print(f'[DBG] message: {message}') | |
| source = tokenizer.apply_chat_template( | |
| message, | |
| add_generation_prompt=True, | |
| return_tensors="pt", | |
| enable_thinking=False | |
| ) | |
| target = example.get("output", "") | |
| if target != "": | |
| target += tokenizer.eos_token | |
| target = tokenizer( | |
| target, | |
| return_attention_mask=False, | |
| add_special_tokens=False, | |
| return_tensors="pt" | |
| ) | |
| target["input_ids"] = target["input_ids"].type(torch.int64) | |
| input_ids = torch.concat((source[0], target["input_ids"][0])) | |
| labels = torch.concat((torch.LongTensor([IGNORE_INDEX] * source[0].shape[0]), target["input_ids"][0])) | |
| self.inp.append(input_ids) | |
| self.label.append(labels) | |
| def __len__(self): | |
| return len(self.inp) | |
| def __getitem__(self, idx): | |
| return self.inp[idx] | |
| class DataCollatorForSupervisedDataset(object): | |
| def __init__(self, tokenizer): | |
| self.tokenizer = tokenizer | |
| def __call__(self, instances): | |
| input_ids, labels = tuple([instance[key] for instance in instances] for key in ("input_ids", "labels")) | |
| input_ids = torch.nn.utils.rnn.pad_sequence( | |
| [torch.tensor(ids) for ids in input_ids], batch_first=True, padding_value=self.tokenizer.pad_token_id | |
| ) | |
| labels = torch.nn.utils.rnn.pad_sequence([torch.tensor(lbls) for lbls in labels], batch_first=True, padding_value=-100) | |
| return dict( | |
| input_ids=input_ids, | |
| labels=labels, | |
| attention_mask=input_ids.ne(self.tokenizer.pad_token_id), | |
| ) | |