Views
No views yet
cxglearner >= 1.3.2 onward, you can run ASE using cxglearner Association module.pip install --upgrade cxglearner.1from cxglearner.config import Config, DefaultConfigs
2from cxglearner.lm import Association
3from cxglearner.encoder import Encoder
4from cxglearner.utils import init_logger
5
6config = Config(DefaultConfigs.eng)
7# Set the specific model
8config.lm.output_path = "CxGrammar/ase-gpt-medium-wiki"
9
10logger = init_logger(config)
11encoder = Encoder(config, logger)
12
13# When instantiating Association, cxglearner will automatically download model parameter files from Huggingface Hub.
14# However, you can also manually download pytorch_model.bin and set the output_path to a local path.
15asso = Association(config, logger, encoder=encoder)
16
17example_sentence = "The wetlands can be more"
18select_mask = ['lexical', 'lexical', 'lexical', 'lexical']
19select_mask = [level_map[level] for level in select_mask]
20select_mask_2 = ['upos', 'lexical', 'lexical', 'lexical']
21select_mask_2 = [level_map[level] for level in select_mask_2]
22
23encoded = encoder.encode(example_sentence, need_ids=True)
24res = encoder.convert_ids_to_tokens([ele[0] for ele in encoded])
25encoded = encoded[1:]
26inputs_1 = [element[select_mask[i]] for i, element in enumerate(encoded)]
27inputs_2 = [element[select_mask_2[i]] for i, element in enumerate(encoded)]
28inputs1_tensor = torch.Tensor(inputs_1).type(torch.int64)
29inputs2_tensor = torch.Tensor(inputs_2).type(torch.int64)
30
31# dynamic candidates
32candidate_dynamic = asso_handler.compute_candidate(inputs_1)
33print(candidate_dynamic)