Views
No views yet
pip install simctg --upgrade1import torch
2# load SimCTG language model
3from simctg.simctggpt import SimCTGGPT
4model_name = r'cambridgeltl/simctg_english_wikipedia'
5model = SimCTGGPT(model_name)
6model.eval()
7tokenizer = model.tokenizer1prefix_text = r"Insect farming is the practice of raising and breeding insects as livestock, also referred to as minilivestock or micro stock. Insects may be farmed for the commodities"
2print ('Prefix is: {}'.format(prefix_text))
3tokens = tokenizer.tokenize(prefix_text)
4input_ids = tokenizer.convert_tokens_to_ids(tokens)
5input_ids = torch.LongTensor(input_ids).view(1,-1)1beam_width, alpha, decoding_len = 5, 0.6, 128
2output = model.fast_contrastive_search(input_ids=input_ids, beam_width=beam_width,
3 alpha=alpha, decoding_len=decoding_len)
4print("Output:\n" + 100 * '-')
5print(tokenizer.decode(output))
6'''
7 Prefix is: Insect farming is the practice of raising and breeding insects as livestock, also referred to as minilivestock or
8 micro stock. Insects may be farmed for the commodities
9 Output:
10 ----------------------------------------------------------------------------------------------------
11 Insect farming is the practice of raising and breeding insects as livestock, also referred to as minilivestock or micro stock.
12 Insects may be farmed for the commodities they produce, such as honey, corn, sorghum, and other crops. In some cases, the
13 production of insects is a way to increase income for the owner or his family. This type of farming has been described as "an
14 economic system that benefits all people regardless of race, sex, or social status" (p. 9). A large number of farmers in North
15 America, Europe, and South America have used the method of farming for food production in order to feed their families and livestock.
16 The most common method of farming is by hand-cropping, which consists of cutting a hole in the ground and using a saw
17'''1@article{su2022contrastive,
2 title={A Contrastive Framework for Neural Text Generation},
3 author={Su, Yixuan and Lan, Tian and Wang, Yan and Yogatama, Dani and Kong, Lingpeng and Collier, Nigel},
4 journal={arXiv preprint arXiv:2202.06417},
5 year={2022}
6}