Views
No views yet
text includes
pragma solidity ^0.5.7ParentAHelloWorld ended with {1# !pip install transformers -q
2
3from transformers import AutoTokenizer, T5ForConditionalGeneration
4
5DEVICE = 'cuda' # fallback to cpu if you do not have cuda
6tokenizer = AutoTokenizer.from_pretrained("hululuzhu/solidity-t5")
7model = T5ForConditionalGeneration.from_pretrained("hululuzhu/solidity-t5").to(DEVICE)
8
9text = """pragma solidity ^0.5.7;
10// Context: ParentA | Functions: helloA helloB | Constants: constantA
11contract HelloWorld is ParentA {"""
12input_ids = tokenizer(text, return_tensors="pt", truncation=True).input_ids.to(DEVICE)
13
14# Need to tune beam/topk/topp params to get good outcome
15generated_ids = model.generate(input_ids, max_length=256, num_beams=5, top_p=0.95, top_k=50)
16print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
17
18# Expect outcome
19"""
20string public constant name = "Hello World";
21...
22uint256 public constant override returns (uint256) {
23return initialSupply;
24}
25function initialSupply() public view returns (uint256) {
26...
27"""pragma solidity 0.5.7;
// Context: PauserRole | Functions: isPauser addPauser renouncePauser | Constants:
contract Pausable is PauserRole {event Paused(address account);
event Unpaused(address account);
bool private _pausableActive;
bool private _paused;
constructor () internal {
_paused = false;
}
function paused() public view returns (bool) {
return _paused;
}
modifier whenNotPaused() {
require(!_paused);
_;
}
modifier whenPaused() {
require(_paused);
_;
}
function pause() public onlyPauser whenNotPaused whenPausableActive {
_paused = true;
emit Paused(msg.sender);
}
function unpause() public onlyPauser whenPaused whenPausableActive {
_paused = false;
emit Unpaused(msg.sender);
}
function _setPausableActive(bool _active) internal {
_pausableActive = _active;
}
modifier whenPausableActive() {
require(_pausableActive);
_;
}
}