Text Classification
Transformers
Safetensors
Russian
bert
spam-detection
russian
Eval Results (legacy)
text-embeddings-inference
Instructions to use RUSpam/spamNS_v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use RUSpam/spamNS_v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="RUSpam/spamNS_v1")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("RUSpam/spamNS_v1") model = AutoModelForSequenceClassification.from_pretrained("RUSpam/spamNS_v1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 2,684 Bytes
e93d1b5 026a940 e93d1b5 3d4a628 e93d1b5 cf2c5c5 6b5dcc4 cf2c5c5 75e7013 e93d1b5 | 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | ---
language: ru
tags:
- spam-detection
- text-classification
- russian
license: cc-by-nc-4.0
datasets:
- RUSpam/spam_dataset_v6
metrics:
- F1
model-index:
- name: spamNS_v1
results:
- task:
name: Классификация текста
type: text-classification
metrics:
- name: F1
type: F1
value: 0.98
---
# RUSpam/spamNS_v1
## Описание
Это модель определения спама, основанная на архитектуре cointegrated/rubert-tiny2, дообученная на русскоязычных данных о спаме. Она классифицирует текст как спам или не спам.
## Использование
```python
import re
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_name = 'RUSpam/spamNS_v1'
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=1).to(device).eval()
tokenizer = AutoTokenizer.from_pretrained(model_name)
def clean_text(text):
text = re.sub(r'http\S+', '', text)
text = re.sub(r'[^А-Яа-я0-9 ]+', ' ', text)
text = text.lower().strip()
return text
def classify_message(message):
message = clean_text(message)
encoding = tokenizer(message, padding='max_length', truncation=True, max_length=128, return_tensors='pt')
input_ids = encoding['input_ids'].to(device)
attention_mask = encoding['attention_mask'].to(device)
with torch.no_grad():
outputs = model(input_ids, attention_mask=attention_mask).logits
pred = torch.sigmoid(outputs).cpu().numpy()[0][0]
is_spam = int(pred >= 0.5)
return is_spam
if __name__ == '__main__':
while True:
message = input("Введите сообщение для классификации (или 'exit' для выхода): ")
if message.lower() == 'exit':
break
is_spam = classify_message(message)
print(f"Сообщение {'является спамом' if is_spam else 'не является спамом'}")
```
## Использование при помощи нашей библиотеки
```python
from ruSpamLib import is_spam
message = input("Введите сообщение: ")
pred_average = is_spam(message, model_name="spamNS_v1")
print(f"Prediction: {'Spam' if pred_average else 'Not Spam'}")
```
# Цитирование
```
@MISC{RUSpam/spamNS_V1,
author = {Kirill Fedko (Neurospacex)},
title = {Russian Spam Classification Model},
url = {https://huggingface.co/RUSpam/spamNS_V1/},
year = 2024
}
``` |