Views
No views yet
1from ruscxnpipe import SemanticSearch
2
3# Initialize with this specific model
4search = SemanticSearch(
5 model_name="Futyn-Maker/ruscxn-embedder",
6 query_prefix="Instruct: Given a sentence, find the constructions of the Russian Constructicon that it contains\nQuery: ",
7 pattern_prefix=""
8)
9
10# Find construction candidates
11examples = ["Петр так и замер.", "Мы, мягко говоря, совсем не ладили."]
12results = search.find_candidates(queries=examples, n=5)
13
14for result in results:
15 print(f"Example: {result['query']}")
16 for candidate in result['candidates']:
17 print(f" Pattern: {candidate['pattern']} (similarity: {candidate['similarity']:.3f})")1from sentence_transformers import SentenceTransformer
2
3model = SentenceTransformer("Futyn-Maker/ruscxn-embedder")
4
5# Note: Use the correct prefixes for optimal performance
6query_prefix = "Instruct: Given a sentence, find the constructions of the Russian Constructicon that it contains\nQuery: "
7pattern_prefix = ""
8
9# Encode a Russian example
10example = query_prefix + "Петр так и замер."
11example_embedding = model.encode(example)
12
13# Encode construction patterns (no prefix needed)
14patterns = [
15 "NP-Nom так и VP-Pfv",
16 "VP вокруг да около",
17 "мягко говоря, Cl"
18]
19pattern_embeddings = model.encode(patterns)
20
21# Calculate similarities
22from sentence_transformers.util import cos_sim
23similarities = cos_sim(example_embedding, pattern_embeddings)
24print(similarities)SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: XLMRobertaModel
(1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
(2): Normalize()
)