Edit model card

You need to agree to share your contact information to access this model

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this model content.

Описание

Это самая новая и точная модель определения спама, основанная на архитектуре руберта, дообученная на русскоязычных данных о спаме. Она классифицирует текст как спам или не спам.

Использование

import re
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_name = 'NeuroSpaceX/ruSpamNS_v6'
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 'не является спамом'}")

Использование при помощи нашей библиотеки

!pip install ruSpam

from ruSpamLib import is_spam

message = input("Введите сообщение: ")

pred_average, confidence = is_spam(message, model_name="spamNS_v6")

print(f"Prediction: {'Spam' if pred_average else 'Not Spam'}")

Лицензия и использование:

При использовании библиотеки в некоммерческих проектах необходимо указывать автора библиотеки — NeuroSpaceX. Либо же ссылку на этот репозиторий. Мой ТГК: https://t.me/spaceneuro Оригинальный бот модератор, работающий на данной модели: @ruSpamNS_bot в тг

Downloads last month
43
Safetensors
Model size
107M params
Tensor type
F32
·
Inference Examples
Unable to determine this model's library. Check the docs .

Space using NeuroSpaceX/ruSpamNS_v6 1

Collection including NeuroSpaceX/ruSpamNS_v6