Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3import json
4
5# 모델 로드
6model_name = "your-username/issue-priority-ko"
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForSequenceClassification.from_pretrained(model_name)
9model.eval()
10
11# 예측 (점수만 출력)
12text = "로그인 안됨, 토큰 만료 처리 필요"
13inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
14
15with torch.no_grad():
16 score_raw = model(**inputs).logits.item() # 0~1 범위 점수
17
18# 원래 스케일로 복원
19with open("score_thresholds.json", "r", encoding="utf-8") as f:
20 thresholds = json.load(f)
21
22score = score_raw * (thresholds["train_max"] - thresholds["train_min"]) + thresholds["train_min"]
23
24print(f"Predicted Score: {score:.4f}")1# 방법 1: to_priority 함수 사용 (권장)
2from postprocess.to_priority import to_priority
3
4# 기본 변환 (후처리 규칙 없음)
5priority = to_priority(score=score, text=text)
6print(f"Priority: {priority}")
7
8# 후처리 규칙 포함 (옵션)
9priority = to_priority(score=score, text=text, use_rules=True)
10print(f"Priority (with rules): {priority}")1# 방법 2: 직접 변환
2if score >= thresholds["q_high"]:
3 priority = "HIGH"
4elif score <= thresholds["q_low"]:
5 priority = "LOW"
6else:
7 priority = "MED"| 항목 | 내용 |
|---|---|
| 기반 모델 | distilbert-base-multilingual-cased |
| 작업 유형 | 회귀 (Regression) |
| 입력 | 커밋/이슈 제목 + 본문 텍스트 |
| 출력 | 우선순위 점수 (float) |
| 클래스 변환 | 후처리로 수행 (to_priority() 함수) |
| 언어 | 한국어, 영어 |
| 최대 길이 | 256 토큰 |
중요: 모델은 점수만 출력합니다. HIGH/MED/LOW 클래스 변환은to_priority()함수를 사용하세요.
postprocess/priority_rules.yaml로 규칙 커스터마이징issue-priority-ko/
├── README.md # 이 파일
├── config.json # 모델 설정
├── model.safetensors # 모델 가중치
├── tokenizer.json # 토크나이저
├── tokenizer_config.json
├── vocab.txt
├── score_thresholds.json # 우선순위 변환 임계값
│
├── postprocess/ # 후처리 규칙 (옵션)
│ ├── to_priority.py # 점수→클래스 변환 함수
│ ├── priority_rules.yaml # 키워드 기반 규칙 (옵션)
│ └── README.md # 후처리 설명
│
├── examples/ # 사용 예제
│ ├── input.json
│ └── output.json
│
└── requirements.txt # 의존성 패키지to_priority() 함수 사용1from postprocess.to_priority import to_priority
2
3# 기본 변환 (threshold 기반)
4priority = to_priority(score=0.82, text="로그인 에러 발생")
5
6# 후처리 규칙 포함 (옵션)
7priority = to_priority(score=0.82, text="로그인 에러 발생", use_rules=True)
8
9# 배치 변환
10from postprocess.to_priority import to_priority_batch
11scores = [0.82, 0.75, 0.90]
12texts = ["로그인 에러", "README 수정", "서버 다운"]
13priorities = to_priority_batch(scores, texts, use_rules=True)postprocess/priority_rules.yaml을 사용하여 키워드 기반 규칙을 적용할 수 있습니다.readme, typo, 문서 → 무조건 LOW장애, 에러, 로그인, 결제 → 최소 MED데이터 손실, 무한, critical → HIGHpostprocess/README.md를 참고하세요.| 지표 | 값 |
|---|---|
| MAE | 0.009 (스케일된 값 기준) |
| RMSE | 0.015 (스케일된 값 기준) |
| Spearman Correlation | 0.85 |
참고: 모델은 상대적 순위 예측에 더 적합합니다. 절대 점수보다는 배치 내 비교를 권장합니다.
1# 모델 예측
2text = "로그인 안됨"
3inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
4with torch.no_grad():
5 score_raw = model(**inputs).logits.item()
6
7# 스케일 복원
8score = score_raw * (thresholds["train_max"] - thresholds["train_min"]) + thresholds["train_min"]
9
10# 클래스 변환
11from postprocess.to_priority import to_priority
12priority = to_priority(score=score, text=text, use_rules=True)1texts = ["이슈1", "이슈2", "이슈3"]
2inputs = tokenizer(texts, return_tensors="pt", truncation=True, max_length=256, padding=True)
3
4with torch.no_grad():
5 scores_raw = model(**inputs).logits.squeeze(-1).numpy()
6
7# 스케일 복원
8scores = scores_raw * (train_max - train_min) + train_min
9
10# 배치 내 상대 정렬 (quantile 기반)
11from scipy.stats import rankdata
12normalized = rankdata(scores, method='average') / len(scores)
13
14# 상위 30% = HIGH, 하위 30% = LOW
15q_high = np.percentile(normalized, 70)
16q_low = np.percentile(normalized, 30)1# 배치 예측
2texts = ["이슈1", "이슈2", "이슈3"]
3inputs = tokenizer(texts, return_tensors="pt", truncation=True, max_length=256, padding=True)
4
5with torch.no_grad():
6 scores_raw = model(**inputs).logits.squeeze(-1).numpy()
7
8# 스케일 복원
9scores = scores_raw * (thresholds["train_max"] - thresholds["train_min"]) + thresholds["train_min"]
10
11# 배치 클래스 변환
12from postprocess.to_priority import to_priority_batch
13priorities = to_priority_batch(scores, texts, use_rules=True)
14
15for text, score, priority in zip(texts, scores, priorities):
16 print(f"{priority}: {score:.4f} - {text}")to_priority() 함수 사용score_thresholds.json으로 원래 스케일 복원 필요priority_rules.yaml은 옵션입니다. 필요시에만 사용examples/ 폴더를 참고하세요.input.json: 입력 예제output.json: 출력 예제postprocess/to_priority.py - 점수→클래스 변환postprocess/priority_rules.yamlpostprocess/README.md