EcomGen-Series
Collection
Generation model for text generation and e-commerce business items • 5 items • Updated
This gemma3 model was trained 2x faster with Unsloth and Huggingface's TRL library.
TorchDynamo를 먼저 비활성화 시키고 진행 시켜야합니다.import os
os.environ["TORCHDYNAMO_DISABLE"] = "1"
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
# Model and Tokenizer Loading
model_name = "UICHEOL-HWANG/EcomGen-Gemma3-4B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto"
)
def generate_product_description(texts):
"""
Generate product description using EcomGen-Gemma3-4B
Args:
texts (str): Input prompt for product description generation
Returns:
str: Generated product description
"""
# Format the input using chat template
messages = [{
"role": "user",
"content": [{"type": "text", "text": texts}]
}]
text = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=False
)
inputs = tokenizer([text], return_tensors="pt").to(model.device)
# Generate response
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=1.0,
top_p=0.95,
top_k=64,
do_sample=True,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id
)
# Decode the response (excluding the input prompt)
response = tokenizer.decode(
outputs[0][inputs['input_ids'].shape[-1]:],
skip_special_tokens=True
)
return response.strip()
# Example Usage
if __name__ == "__main__":
# Example 1: Product description generation
prompt = """상품명: 프리미엄 유기농 쌀 10kg
카테고리: 식품 > 쌀·잡곡
가격: 45,000원
핵심 키워드: 유기농, 쌀, 농부, 정성, 고가, 품질, 안전, 가족, 건강
작성 톤: 신뢰감_있는_전문가_톤 (품질 중심, 프리미엄 상품 강조)"""
result = generate_product_description(prompt)
print("Generated Product Description:")
print(result)
# Example 2: Different product category
prompt2 = """상품명: 무선 블루투스 이어폰 AirPods Pro
카테고리: 전자제품 > 오디오
가격: 329,000원
핵심 키워드: 무선, 블루투스, 노이즈캔슬링, 프리미엄, 애플, 고음질
작성 톤: 트렌디한_젊은_톤 (기술과 라이프스타일 강조)"""
result2 = generate_product_description(prompt2)
print("\nGenerated Product Description 2:")
print(result2)
Base model
google/gemma-3-4b-pt