Views
No views yet

1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
4model_id = "Easy-Systems/easy-ko-gemma-2-9b-it-v1"
5model = AutoModelForCausalLM.from_pretrained(model_id,
6 attn_implementation="eager",
7 torch_dtype=torch.bfloat16,
8 device_map="auto")
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11prompt=""
12
13messages = [
14 {"role": "user", "content": "당신은 친절한 AI chatbot 입니다. 요청에 대해서 한국어로 답변해주세요.\n" + prompt},
15]
16input_ids = tokenizer.apply_chat_template(
17 messages,
18 add_generation_prompt=True,
19 return_tensors="pt"
20).to(model.device)
21
22outputs = model.generate(
23 input_ids,
24 max_new_tokens=2048,
25 do_sample=True,
26 temperature=0.3,
27 repetition_penalty=1.1,
28 top_p=0.95,
29 top_k=40,
30)
31
32response = outputs[0][input_ids.shape[-1]:]
33print(tokenizer.decode(response, skip_special_tokens=True).strip())
34f(x) = 3x^3 + 2x^2 + 58의 미분은 다음과 같습니다.
f'(x) = 9x^2 + 4x
f'(x)를 한 번 더 미분하면 다음과 같습니다.
f''(x) = 18x + 4
민수는 노란색 셔츠 다섯 벌을 가지고 있습니다. 노란색 바지의 수는 민수가 가지고 있는 셔츠의 색상과 관련이 없습니다. 따라서 민수는 여전히 5벌의 노란색 셔츠를 가지고 있을 것입니다.
민수가 가지고 있는 셔츠들의 색상을 모두 섞으면 무슨 색이 될까요? 물감의 경우와 빛의 경우를 모두 설명해 드리겠습니다.
물감: 빨간색과 노란색을 섞으면 주황색이 됩니다. 따라서 민수가 가지고 있는 모든 셔츠를 섞으면 주황색이 될 것입니다.
빛: 빨간색과 노란색을 섞으면 주황색이 됩니다. 이는 물감과 같은 원리로 작동합니다. 하지만, 빛은 다른 색상의 빛을 흡수하고 반사하는 방식으로 작동하기 때문에, 빨간색과 노란색 빛을 섞으면 주황색 빛이 생성됩니다
def find_unique_character(characters):
"""
주어진 리스트에서 중복되지 않는 첫 번째 문자를 반환하는 함수
Args:
characters: 문자열 리스트
Returns:
중복되지 않는 첫 번째 문자
"""
for char in characters:
if characters.count(char) == 1:
return char
# 예시 사용
print(find_unique_character(['a', 'b', 'c', 'a', 'd'])) # 출력: b
print(find_unique_character(['a', 'b', 'a', 'b', 'c'])) # 출력: c
print(find_unique_character(['a', 'b', 'c', 'd', 'e'])) # 출력: a
설명:
함수 정의: find_unique_character(characters) 함수를 정의합니다. 이 함수는 문자열 리스트 characters를 입력으로 받습니다.
반복문: for char in characters: 문을 사용하여 리스트의 각 문자를 순회합니다.
중복 확인: characters.count(char) == 1 을 사용하여 현재 문자 char가 리스트에서 한 번만 나타나는지 확인합니다.
반환: 만약 중복되지 않는 첫 번째 문자를 찾으면, 바로 해당 문자를 반환합니다.
예시 사용:
코드의 예시 부분은 함수를 사용하여 다양한 입력 리스트에 대해 테스트하는 방법을 보여줍니다. 각 테스트 케이스는 find_unique_character() 함수를 호출하고 출력 결과를 표시합니다.