Views
No views yet
1import tensorflow as tf
2from transformers import TFGPT2LMHeadModel, GPT2Tokenizer
3
4tokenizer = GPT2Tokenizer.from_pretrained("benkimz/agbrain")
5model = TFGPT2LMHeadModel.from_pretrained("benkimz/agbrain")
6
7prompt = """
8I think agribusiness is a great opportunity for passionate
9investors. From food business to growing crops for sale,
10and rearing livestock for business.
11"""
12
13input_ids = tokenizer.encode(prompt, return_tensors="tf")
14outputs = model.generate(input_ids=input_ids,
15 max_length=120,
16 do_sample=True)
17generated_text = tokenizer.decode(outputs[0],
18 skip_special_tokens=True)
19
20print(generated_text)
21
22# Output
23"""
24I think agribusiness is a great opportunity for passionate
25investors. From food business to growing crops for sale,
26and rearing livestock for business.
27
28In this paper I will introduce a concept model agribusiness
29that focuses on businesses to grow large amounts of product.
30 This model requires that product be sold outside of
31agriculture industry, thus allowing farmers advantages,
32especially over agronomic competition in production.
33model is very important to farmers as it will be possible,
34to sell their products at local markets without
35"""1from transformers import pipeline, set_seed
2generator = pipeline('text-generation', model='benkimz/agbrain')
3set_seed(42)
4
5samples = generator(
6 "Animal husbandry is an important part of livestock production.",
7 max_length=100,
8 num_return_sequences=2
9)
10
11for sample in samples:
12 print("Model output: {}\n".format(sample['generated_text']))
13
14
15# Output
16"""
17**Model output**: Animal husbandry is an important part of
18livestock production. livestock production industry is complex,
19many factors contribute to this complexity. need to determine
20most efficient method of handling livestock to ensure best quality
21product. It is important that animals being handled appropriately
22have properly cleaned equipment that prevents scratching
23(Sappell 2002). Because livestock is an important part of
24livestock production, veterinary care must be taken regularly
25during transport of animals from a farm to your home to be
26successful. If livestock were to be
27
28**Model output**: Animal husbandry is an important part of
29livestock production. Animal husbandry combines various
30strategies to control pests. Management strategies of pest
31management strategies
32Preventing pest from reaching level
33 Preventing pest from reaching level
34To minimize transmission costs, control mechanisms
35 must be developed to prevent pest from reaching level. In
36order to have an accurate information about pest
37management methods, instrumental field study of pest management
38measures be developed by field of study. A technique of this
39"""| Step | Training Loss |
|---|---|
| 500 | 3.877700 |
| 1000 | 3.746200 |
| 1500 | 3.659600 |
| 2000 | 3.613300 |
| 2500 | 3.603400 |
| 3000 | 3.561600 |
| 3500 | 3.558300 |
| 4000 | 3.518400 |
| 4500 | 3.504100 |
| 5000 | 3.508600 |