Views
No views yet
1pip install sgnlp
21from sgnlp.models.coherence_momentum import CoherenceMomentumModel, CoherenceMomentumConfig, \
2 CoherenceMomentumPreprocessor
3
4# Load Model
5config = CoherenceMomentumConfig.from_pretrained(
6 "https://storage.googleapis.com/sgnlp-models/models/coherence_momentum/config.json"
7)
8model = CoherenceMomentumModel.from_pretrained(
9 "https://storage.googleapis.com/sgnlp-models/models/coherence_momentum/pytorch_model.bin",
10 config=config
11)
12
13preprocessor = CoherenceMomentumPreprocessor(config.model_size, config.max_len)
14
15# Example text inputs
16text1 = "Companies listed below reported quarterly profit substantially different from the average of analysts ' " \
17 "estimates . The companies are followed by at least three analysts , and had a minimum five-cent change in " \
18 "actual earnings per share . Estimated and actual results involving losses are omitted . The percent " \
19 "difference compares actual profit with the 30-day estimate where at least three analysts have issues " \
20 "forecasts in the past 30 days . Otherwise , actual profit is compared with the 300-day estimate . " \
21 "Source : Zacks Investment Research"
22text2 = "The companies are followed by at least three analysts , and had a minimum five-cent change in actual " \
23 "earnings per share . The percent difference compares actual profit with the 30-day estimate where at least " \
24 "three analysts have issues forecasts in the past 30 days . Otherwise , actual profit is compared with the " \
25 "300-day estimate . Source : Zacks Investment Research. Companies listed below reported quarterly profit " \
26 "substantially different from the average of analysts ' estimates . Estimated and actual results involving " \
27 "losses are omitted ."
28
29text1_tensor = preprocessor([text1])
30text2_tensor = preprocessor([text2])
31
32text1_score = model.get_main_score(text1_tensor["tokenized_texts"]).item()
33text2_score = model.get_main_score(text2_tensor["tokenized_texts"]).item()
34
35print(text1_score, text2_score)
36
37