forked from tintinweb/hallucinate.sol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
323 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"name": "tutorial-2-hallucinate-from-pretrained-model.ipynb", | ||
"provenance": [], | ||
"collapsed_sections": [] | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
}, | ||
"accelerator": "GPU" | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "Vycsyjqdsk6D" | ||
}, | ||
"source": [ | ||
"[<img width=\"200\" alt=\"get in touch with Consensys Diligence\" src=\"https://user-images.githubusercontent.com/2865694/56826101-91dcf380-685b-11e9-937c-af49c2510aa0.png\">](https://diligence.consensys.net)<br/>\n", | ||
"<sup>\n", | ||
"[[ 🌐 ](https://diligence.consensys.net) [ 📩 ](https://github.com/ConsenSys/vscode-solidity-doppelganger/blob/master/mailto:[email protected]) [ 🔥 ](https://consensys.github.io/diligence/)]\n", | ||
"</sup><br/><br/>\n", | ||
"\n", | ||
"\n", | ||
"# Hallucinate.sol - from pre-trained model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "qccfvi1fkbNK" | ||
}, | ||
"source": [ | ||
"## Initialization magic\n", | ||
"\n", | ||
"We're training on google collab because it is much faster than on a normal pc. For this, we'll want to make the modules that download the source-samples and thrain the RNN available on google drive.\n", | ||
"\n", | ||
"1. copy the files from https://github.com/tintinweb/hallucinate.sol to your personal google drive into `/MyDrive/collab/solidity-gen`\n", | ||
"2. run the next two steps and provide your authenticator token \n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "OpWgMJEZ9wz7" | ||
}, | ||
"source": [ | ||
"%tensorflow_version 2.x" | ||
], | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "H7ZRJKel9LaW", | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"outputId": "7c69d1a2-d50f-4375-e331-369ea5e01dbc" | ||
}, | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"# (a) mount the google drive in order for the code to find the soliditygen module\n", | ||
"\n", | ||
"from google.colab import drive\n", | ||
"drive.mount('/content/drive', force_remount=True)\n", | ||
"os.chdir('/content/drive/MyDrive/collab/solidity-gen')\n", | ||
"!ls -lsat '/content/drive/MyDrive/collab/solidity-gen'\n", | ||
"\n", | ||
"\"\"\"\n", | ||
"# (b) checkout the repo instead\n", | ||
"\n", | ||
"!git clone https://github.com/tintinweb/hallucinate.sol.git\n", | ||
"os.chdir(\"hallucinate.sol\")\n", | ||
"\"\"\"\n", | ||
"\n", | ||
"### import everything because we're lazy\n", | ||
"from soliditygen import *" | ||
], | ||
"execution_count": 16, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"Mounted at /content/drive\n", | ||
"total 87\n", | ||
" 3 -rw------- 1 root root 2868 Nov 12 10:59 tutorial-2-hallucinate-from-pretrained-model.ipynb\n", | ||
" 1 -rw------- 1 root root 103 Nov 12 10:41 README.md\n", | ||
"57 -rw------- 1 root root 57752 Nov 12 10:38 tutorial-1-train_and_predict.ipynb\n", | ||
" 4 drwx------ 2 root root 4096 Nov 12 10:33 solidity_model_text\n", | ||
" 9 -rw------- 1 root root 8299 Nov 12 10:27 soliditygen.py\n", | ||
" 2 -rw------- 1 root root 1610 Nov 12 09:48 .gitignore\n", | ||
" 4 drwx------ 2 root root 4096 Nov 12 09:24 .git\n", | ||
" 4 drwx------ 2 root root 4096 Nov 10 10:40 training_checkpoints\n", | ||
" 4 drwx------ 2 root root 4096 Nov 10 09:32 __pycache__\n" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "vEAIKCt3naTI" | ||
}, | ||
"source": [ | ||
"## Load an existing model\n", | ||
"\n", | ||
"Restore the saved state from local folder `solidity_model`, then, hallucinate more solidity code 🙌" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "Elf61diwlIPn" | ||
}, | ||
"source": [ | ||
"### creat dummy trainingData object and load existing state from the local dir\n", | ||
"trainingData = TrainingData()\n", | ||
"trainingData.load_model(\"solidity_model_text\") # location of model\n" | ||
], | ||
"execution_count": 17, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "dfzpTwkTsUk-" | ||
}, | ||
"source": [ | ||
"## Predict \n", | ||
"\n", | ||
"Hallucinate more solidity 🙌" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "NzWXr0nXsTuI", | ||
"outputId": "ce20954a-067a-46de-c204-ef2bafee84fa" | ||
}, | ||
"source": [ | ||
"start = time.time()\n", | ||
"textOut = trainingData.predict(['contract '], 3000)\n", | ||
"print(textOut, '\\n\\n' + '_'*80)\n", | ||
"end = time.time()\n", | ||
"print('\\nRun time:', end - start)" | ||
], | ||
"execution_count": 18, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"contract Ownable {\n", | ||
" address public owner;\n", | ||
" event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n", | ||
" function Ownable() public {\n", | ||
" owner = msg.sender;\n", | ||
" }\n", | ||
" modifier onlyOwner() {\n", | ||
" require(msg.sender == owner);\n", | ||
" _;\n", | ||
" }\n", | ||
" function transferOwnership(address newOwner) public onlyOwner {\n", | ||
" require(newOwner != address(0));\n", | ||
" emit OwnershipTransferred(owner, newOwner);\n", | ||
" owner = newOwner;\n", | ||
" }\n", | ||
"}\n", | ||
"contract Parminicinvition is Ownable {\n", | ||
" using SafeMath for uint256;\n", | ||
" enum State { Approve = token.totalSupply();\n", | ||
" require(tokens >= summaryTokens.add(bonus));\n", | ||
" totalDailydested = totalEthInWei + msg.value;\n", | ||
" totalSoldTokens = token.totalSupply();\n", | ||
" emit Transfer(address(0), 0xCf49B9298aC4d4933a7D6984d89A49aDc84A6CA602BA513D872C3,21f36325D28718](0));\n", | ||
" totalSupply = totalSupply.mul(totalValue.add(soldSignedMap[tokensBough.mul(1)));\n", | ||
" restributedPluyRates[msg.sender] = true;\n", | ||
" nonStokenSupplyFinallow\n", | ||
" }\n", | ||
" if(opits[msg.sender].amount <= totalSupply)) ether;\n", | ||
"\t\t\t}\n", | ||
"\t\tassignOpe(address(this).balance, weiAmount);\n", | ||
"\t\trequire(canTra_secrecover(_approved) >= rNo(_reward, _weight, _amount);\n", | ||
"\t totalAmount = totalAmount.add(_amount);\n", | ||
" Transfer(_addr, msg.sender, amount);\n", | ||
" }\n", | ||
" function checkRollUnerad(address _caller) external {\n", | ||
" require(activeTransieronase / _values[i] >= eth[i] && _patent.beneficiary != address(0));\n", | ||
" require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);\n", | ||
" uint256 _tokens = _amountOfTokens;\n", | ||
" uint256 _ethereum = tokensToEthereum_(_tokens, _taxedEthereum);\n", | ||
" uint256 _divTokens = getToken().balanceOf(_owner);\n", | ||
" require(_tokenAddress >= _value);\n", | ||
" allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);\n", | ||
" }\n", | ||
" function multiSigWallet(address[] _KeceiveAddress(address _whenAddress) onlyOwner public {\n", | ||
" stats[msg.sender][_i] = _getUnlockedAmt;\n", | ||
" }\n", | ||
" function enableKYC() external onlyOwner beforeURe {\n", | ||
" uint256 lastIndex = 0;\n", | ||
" address _tokenAddress indexe msg.sender;\n", | ||
" uint128 accountKey = uint128(_affidiets, userTrustedContribution);\n", | ||
" assignUpgredateTokens(_address, _beneficiever, _tokens);\n", | ||
" }\n", | ||
" function setRestrictAddressLass() onlyOwnerships onlyWhitelisted r\n", | ||
" uint256 _remainingTokens = \n", | ||
" (_tokenPriceInitial * tokenPriceIncremental_ * (_tokenSupply/1e18);\n", | ||
" uint depositAmount = deadline );\n", | ||
" }\n", | ||
" isReleaseAgent = addr;\n", | ||
" }\n", | ||
" function paymentSuspendedPaymentsale(uint256[] _users, uint256[] _scriptLogoAssess) public payable returns(uint256[12] _eth) {\n", | ||
" k.cards[0x343C2593c3216d33433D43fBBF6cF7 = txp1 * item_iXCalculated[_userNumber].enity_inceent, 0.0000001 ether, other.umLock());\n", | ||
" }\n", | ||
" function buyTokens(address _address) external onlyWhileOter{\n", | ||
" uint256 inReadyToBivs;\n", | ||
" totalSupply = totalSupply.sub(_amount);\n", | ||
" DistrustedContributionTime = _block.pixe \n", | ||
"\n", | ||
"________________________________________________________________________________\n", | ||
"\n", | ||
"Run time: 16.05377769470215\n" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |