File size: 1,849 Bytes
44cc602
 
 
 
 
 
 
 
 
ada49c5
44cc602
ce072c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
language:
- en
pipeline_tag: text-classification
tags:
- url
- urls
- classification
new_version: CrabInHoney/urlbert-tiny-base-v2
---
This is a very small version of BERT, intended for later fine-tune under URL analysis.

Model size
6.53M params

Tensor type
F32

Test example:

    from transformers import BertTokenizerFast, BertForMaskedLM, pipeline
    import torch
    
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    print(f"Используемое устройство: {device}")
    
    model_path = "./urlbertV1"
    
    tokenizer = BertTokenizerFast.from_pretrained(model_path)
    
    model = BertForMaskedLM.from_pretrained(model_path)
    model.to(device)
    
    fill_mask = pipeline(
        "fill-mask",
        model=model,
        tokenizer=tokenizer,
        device=0 if torch.cuda.is_available() else -1
    )
    
    sentences = [
        "http://helloworld.[MASK]/events/"
    ]
    
    for sentence in sentences:
        print(f"\nИсходное предложение: {sentence}")
        results = fill_mask(sentence)
        for result in results:
            token_str = result['token_str']
            score = result['score']
            print(f"Предсказанное слово: {token_str}, вероятность: {score:.4f}")
			
Output:

Исходное предложение: http://helloworld.[MASK]/events/

Предсказанное слово: com, вероятность: 0.7575

Предсказанное слово: org, вероятность: 0.0884

Предсказанное слово: nl, вероятность: 0.0294

Предсказанное слово: net, вероятность: 0.0198

Предсказанное слово: ca, вероятность: 0.0153


## License

[MIT](https://choosealicense.com/licenses/mit/)