Views
No views yet
1from sentence_transformers import SentenceTransformer
2import numpy as np
3
4# Load model
5model = SentenceTransformer('swan07/bert-authorship-verification')
6
7# Encode texts
8text1 = "Your first text here"
9text2 = "Your second text here"
10
11emb1 = model.encode(text1)
12emb2 = model.encode(text2)
13
14# Calculate cosine similarity
15similarity = np.dot(emb1, emb2) / (np.linalg.norm(emb1) * np.linalg.norm(emb2))
16
17# Predict
18prediction = "Same Author" if similarity >= 0.5 else "Different Authors"
19print(f"Prediction: {prediction}")
20print(f"Similarity: {similarity:.3f}")1@article{manolache2021transferring,
2 title={Transferring BERT-like Transformers' Knowledge for Authorship Verification},
3 author={Manolache, Andrei and Brad, Florin and Burceanu, Elena and Barbalau, Antonio and Ionescu, Radu Tudor and Popescu, Marius},
4 journal={arXiv preprint arXiv:2112.05125},
5 year={2021}
6}