hululuzhu commited on
Commit
73ef5f5
1 Parent(s): 6c38849

Updated code snippets for testing

Browse files
Files changed (1) hide show
  1. README.md +39 -4
README.md CHANGED
@@ -6,6 +6,7 @@ tags:
6
  - solidity
7
  - web3
8
  - code generation
 
9
  widget:
10
  - text: "pragma solidity ^0.5.7;\n// Context: ParentA | Functions: helloA helloB | Constants: constantA \ncontract HelloWorld is ParentA {"
11
  ---
@@ -17,18 +18,52 @@ widget:
17
  - Contract/Library/Interface declaration header, e.g. `HelloWorld` ended with `{`
18
 
19
  ```python
 
 
20
  from transformers import AutoTokenizer, T5ForConditionalGeneration
 
 
21
  tokenizer = AutoTokenizer.from_pretrained("hululuzhu/solidity-t5")
22
- model = T5ForConditionalGeneration.from_pretrained("hululuzhu/solidity-t5")
23
 
24
  text = """pragma solidity ^0.5.7;
25
  // Context: ParentA | Functions: helloA helloB | Constants: constantA
26
  contract HelloWorld is ParentA {"""
27
- input_ids = model.tokenizer(text, return_tensors="pt", truncation=True).input_ids.to('cuda')
28
 
29
  # Need to tune beam/topk/topp params to get good outcome
30
- generated_ids = model.model.generate(input_ids, max_length=256, num_beams=5, top_p=0.95, top_k=50)
31
- print(model.tokenizer.decode(generated_ids[0], skip_special_tokens=True))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  ```
33
 
34
 
 
6
  - solidity
7
  - web3
8
  - code generation
9
+ - smart contract
10
  widget:
11
  - text: "pragma solidity ^0.5.7;\n// Context: ParentA | Functions: helloA helloB | Constants: constantA \ncontract HelloWorld is ParentA {"
12
  ---
 
18
  - Contract/Library/Interface declaration header, e.g. `HelloWorld` ended with `{`
19
 
20
  ```python
21
+ # !pip install transformers -q
22
+
23
  from transformers import AutoTokenizer, T5ForConditionalGeneration
24
+
25
+ DEVICE = 'cuda' # fallback to cpu if you do not have cuda
26
  tokenizer = AutoTokenizer.from_pretrained("hululuzhu/solidity-t5")
27
+ model = T5ForConditionalGeneration.from_pretrained("hululuzhu/solidity-t5").to(DEVICE)
28
 
29
  text = """pragma solidity ^0.5.7;
30
  // Context: ParentA | Functions: helloA helloB | Constants: constantA
31
  contract HelloWorld is ParentA {"""
32
+ input_ids = tokenizer(text, return_tensors="pt", truncation=True).input_ids.to(DEVICE)
33
 
34
  # Need to tune beam/topk/topp params to get good outcome
35
+ generated_ids = model.generate(input_ids, max_length=256, num_beams=5, top_p=0.95, top_k=50)
36
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
37
+
38
+ # Expect outcome
39
+ """
40
+ string public constant name = "Hello World";
41
+ string public constant symbol = "HELPER";
42
+ uint8 public constant decimals = 18;
43
+ uint256 public constant initialSupply = 0;
44
+ uint256 public constant override returns (uint256) {
45
+ return initialSupply;
46
+ }
47
+ function initialSupply() public view returns (uint256) {
48
+ return initialSupply;
49
+ }
50
+ function balanceOf(address _owner) public view returns (uint256) {
51
+ return balanceOf(_owner);
52
+ }
53
+ function transfer(address _to, uint256 _value) public returns (bool) {
54
+ balanceOf[msg.sender] -= _value;
55
+ balanceOf[_to] += _value;
56
+ emit Transfer(msg.sender, _to, _value);
57
+ return true;
58
+ }
59
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
60
+ balanceOf[_from] -= _value;
61
+ balanceOf[_to] += _value;
62
+ emit Transfer(_from, _to, _value);
63
+ return true;
64
+ }
65
+ function approve(address _spender, uint256 _value) public returns (bool)
66
+ """
67
  ```
68
 
69