Views
No views yet
1from transformers import T5TokenizerFast, T5ForConditionalGeneration, pipeline
2
3# 모델 경로 및 cpu, gpu 지정
4cache_dir = "./hugging_face"
5gentle_model_path='9unu/formal_speech_translation'
6gentle_model = T5ForConditionalGeneration.from_pretrained(formal_model_path, cache_dir=cache_dir)
7device = torch.device("cuda" if torch.cuda.is_available() else "cpu")1# transformers 파이프라인 생성
2gentle_pipeline = pipeline(model = gentle_model, tokenizer = tokenizer, device = device, max_length=60)
3
4# text 말투 변환
5text = "밥 먹는 중이야"
6num_return_sequences = 1
7max_length = 60
8out = gentle_pipeline(text, num_return_sequences = num_return_sequences, max_length=max_length)
9print([x['generated_text'] for x in out])