File size: 1,878 Bytes
1abaa49
078820f
1abaa49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
078820f
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
---
license: apache-2.0
language:
- en
pipeline_tag: text-classification
tags:
- url
- urls
- classification
---
This is a very small version of BERT, intended for later fine-tune under URL analysis.


An updated version of the old basic model for URL analysis

Old version: https://huggingface.co/CrabInHoney/urlbert-tiny-base-v2

Model size

3.69M 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_name = "CrabInHoney/urlbert-tiny-base-v3"
    
    tokenizer = BertTokenizerFast.from_pretrained(model_name)
    model = BertForMaskedLM.from_pretrained(model_name)
    model.to(device)
    
    fill_mask = pipeline(
        "fill-mask",
        model=model,
        tokenizer=tokenizer,
        device=0 if torch.cuda.is_available() else -1
    )
    
    sentences = [
        "http://example.[MASK]/"
    ]
    
    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://example.[MASK]/

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

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

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

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

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