File size: 2,258 Bytes
4cab0fc
 
 
 
 
 
 
 
2ac55ff
4cab0fc
 
 
 
 
dee8787
2f72338
4cab0fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0147d71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f72338
0147d71
 
 
1ac96d4
0147d71
 
 
 
 
 
 
 
 
e87e483
2f72338
e87e483
0147d71
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
license: apache-2.0
tags:
- generated_from_trainer
metrics:
- accuracy
model-index:
- name: bert-uncased-base
---
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
should probably proofread and complete it, then remove this comment. -->

# bert-uncased-base

This model is a fine-tuned version of [bert-base-uncased](https://huggingface.co/bert-base-uncased) on an Reddit-dialogue dataset.
This model can be used for Text Classification: Given two sentences, see if they are related.
It achieves the following results on the evaluation set:
- Loss: 0.2297
- Accuracy: 0.9267

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 2e-05
- train_batch_size: 320
- eval_batch_size: 80
- seed: 42
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- num_epochs: 5.0

### Training results



### Framework versions

- Transformers 4.16.0.dev0
- Pytorch 1.10.1+cu102
- Datasets 1.17.0
- Tokenizers 0.11.0

## Usage (HuggingFace Transformers)
You can use the model like this: 

```python
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

# label_list
label_list = ['matched', 'unmatched']

# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained("Fan-s/reddit-tc-bert", use_fast=True)
model = AutoModelForSequenceClassification.from_pretrained("Fan-s/reddit-tc-bert") 

# Set the input
post = "don't make gravy with asbestos."
response = "i'd expect someone with a culinary background to know that. since we're talking about school dinner ladies, they need to learn this pronto."

# Predict whether the two sentences are matched 
def predict(post, response, max_seq_length=128):
    with torch.no_grad():
        args =  (post, response)
        input = tokenizer(*args, padding="max_length", max_length=max_seq_length, truncation=True, return_tensors="pt")
        output = model(**input)
        logits = output.logits
        item = torch.argmax(logits, dim=1)
        predict_label = label_list[item]
        return predict_label, logits
         
predict_label, logits = predict(post, response)
# Matched
print("predict_label:", predict_label)
```