Views
No views yet
| train_loss | val_loss | acc | epoch | batch | lr |
|---|---|---|---|---|---|
| 0.326 | 0.538 | 0.811 | 3 | 32 | 2e-5 |
1class ArgumentHandler(ABC):
2 """
3 Base interface for handling arguments for each :class:`~transformers.pipelines.Pipeline`.
4 """
5
6 @abstractmethod
7 def __call__(self, *args, **kwargs):
8 raise NotImplementedError()
9
10
11class CustomZeroShotClassificationArgumentHandler(ArgumentHandler):
12 """
13 Handles arguments for zero-shot for text classification by turning each possible label into an NLI
14 premise/hypothesis pair.
15 """
16
17 def _parse_labels(self, labels):
18 if isinstance(labels, str):
19 labels = [label.strip() for label in labels.split(",")]
20 return labels
21
22 def __call__(self, sequences, labels, hypothesis_template):
23 if len(labels) == 0 or len(sequences) == 0:
24 raise ValueError("You must include at least one label and at least one sequence.")
25 if hypothesis_template.format(labels[0]) == hypothesis_template:
26 raise ValueError(
27 (
28 'The provided hypothesis_template "{}" was not able to be formatted with the target labels. '
29 "Make sure the passed template includes formatting syntax such as {{}} where the label should go."
30 ).format(hypothesis_template)
31 )
32
33 if isinstance(sequences, str):
34 sequences = [sequences]
35 labels = self._parse_labels(labels)
36
37 sequence_pairs = []
38 for label in labels:
39 # 수정부: 두 문장을 페어로 입력했을 때, `token_type_ids`가 자동으로 붙는 문제를 방지하기 위해 미리 두 문장을 `sep_token` 기준으로 이어주도록 함
40 sequence_pairs.append(f"{sequences} {tokenizer.sep_token} {hypothesis_template.format(label)}")
41
42 return sequence_pairs, sequences1classifier = pipeline(
2 "zero-shot-classification",
3 args_parser=CustomZeroShotClassificationArgumentHandler(),
4 model="pongjin/roberta_with_kornli"
5)1sequence = "배당락 D-1 코스피, 2330선 상승세...외인·기관 사자"
2candidate_labels =["외환",'환율', "경제", "금융", "부동산","주식"]
3
4classifier(
5 sequence,
6 candidate_labels,
7 hypothesis_template='이는 {}에 관한 것이다.',
8)
9
10>>{'sequence': '배당락 D-1 코스피, 2330선 상승세...외인·기관 사자',
11 'labels': ['주식', '금융', '경제', '외환', '환율', '부동산'],
12 'scores': [0.5052872896194458,
13 0.17972524464130402,
14 0.13852974772453308,
15 0.09460823982954025,
16 0.042949128895998,
17 0.038900360465049744]}