CrabInHoney commited on
Commit
cd926ec
·
verified ·
1 Parent(s): af17464

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +77 -3
README.md CHANGED
@@ -1,3 +1,77 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ pipeline_tag: text-classification
6
+ tags:
7
+ - url
8
+ - urls
9
+ - classification
10
+ ---
11
+ This is a very small version of BERT, intended for later fine-tune under URL analysis.
12
+
13
+ An updated, lighter version of the old basic model for URL analysis
14
+
15
+ Old version: https://huggingface.co/CrabInHoney/urlbert-tiny-base-v1
16
+
17
+ Model size
18
+
19
+ 3.7M params
20
+
21
+ Tensor type
22
+
23
+ F32
24
+
25
+ Test example:
26
+
27
+ from transformers import BertTokenizerFast, BertForMaskedLM, pipeline
28
+ import torch
29
+
30
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
31
+ print(f"Используемое устройство: {device}")
32
+
33
+ model_path = "./urlbertV2"
34
+
35
+ tokenizer = BertTokenizerFast.from_pretrained(model_path)
36
+
37
+ model = BertForMaskedLM.from_pretrained(model_path)
38
+ model.to(device)
39
+
40
+ fill_mask = pipeline(
41
+ "fill-mask",
42
+ model=model,
43
+ tokenizer=tokenizer,
44
+ device=0 if torch.cuda.is_available() else -1
45
+ )
46
+
47
+ sentences = [
48
+ "http://example.[MASK]//"
49
+ ]
50
+
51
+ for sentence in sentences:
52
+ print(f"\nИсходное предложение: {sentence}")
53
+ results = fill_mask(sentence)
54
+ for result in results:
55
+ token_str = result['token_str']
56
+ score = result['score']
57
+ print(f"Предсказанное слово: {token_str}, вероятность: {score:.4f}")
58
+
59
+ Output:
60
+
61
+ Исходное предложение: http://example.[MASK]//
62
+
63
+ Предсказанное слово: com, вероятность: 0.6949
64
+
65
+ Предсказанное слово: org, вероятность: 0.1261
66
+
67
+ Предсказанное слово: nl, вероятность: 0.0318
68
+
69
+ Предсказанное слово: net, вероятность: 0.0168
70
+
71
+ Предсказанное слово: co, вероятность: 0.0140
72
+
73
+
74
+
75
+ ## License
76
+
77
+ [MIT](https://choosealicense.com/licenses/mit/)