# Smart Contract Generation Assisted by AI-Based Word Segmentation
## 5 Word Segmentation by Separation Inference
### SpIn-Based Word Segmentation Mechanism  
WS by SpIn is the process of annotating the word boundaries with a set of predefined tags, as illustrated in Figure 2a, where segmentation is enclosed by the \"B\" and \"E\" tags. The correct and wrong segmentations are posited on the left and the right, respectively, in Figure 2a. Further observing the correct word segmentation (indicated by the red arrow) and the wrong word segmentation (indicated by the pink arrow) in Figure 2b, we can find that the inaccurate tag transition brings ambiguity. The potential segmentations caused by ambiguities are the segmentation of \"mayor\" and \"bridge\" are in the right half. The ambiguity is caused by the weakness of the word segmentation algorithm. Therefore, improving the word segmentation algorithm is critical for ensuring accurate semantic exchange. In addition, it is essential for providing accurate recommendation words to editors, especially in the smart contract generation that requires semantic consistency and common consent. Since existing methods treat WS as the sequence tagging task, different tagging schemas such as \"BMES\", \"BIS\", \"START-NONSTART\", and \"Sep-App\" are introduced. Despite different meanings, all these tagging schemas present implied position information of the current character (e.g., \"Begin\", \"Middle\", or \"End\" in the segmentation). The implied position limits transitions between tags. Take the \"BMES\" tagging schema for an instance, the tag \"B\" must be followed by \"M\" or \"E\". In addition, the tag of the first character in a sentence must be \"B\". Therefore, CRF is leveraged to constrain unreasonable tag transition. Applied CWS methods based on tagging schemas aim to attain the optimal tag transferring sequence rendered in red arrows as in Figure 2b. The CRF has alleviated the unreasonable tag prediction to some degree. However, the intrinsic weakness of existing tagging schemas, which is the implied restriction of position, is not well addressed. Relying on the state-of-the-art performance of our proposed SpIn, we, therefore, introduce it into the AIASCG framework to ensure the accuracy of the recommendation word. As depicted in Figure 2c, for every two characters (Chinese characters in this example), they are either adhered to form (a part of) a complete semantic concept (a Chinese word in the example) or separated as they belong to distinct concepts. In other words, the connection state between every two neighboring characters can be described as  
Figure 2: Existing WS algorithm vs. Proposed SpIn. The Chinese sentece indicates “Nanjing Yangtze River Bridge”. (**a**) is the input sentence with its ground-truth segmentation at the left half and its potential segmentation on the right half. The proper word segmentation (left, about the bridge) and the improper segmentation (right, about the mayor) of the input. In (**b**), red arrows and circles stand for the correct tag sequence while the pink ones are improper. Existing WS algorithm based on the _BMES_ tagging schema. In (**c**), states between characters rendered by red are the correct ones. Substituting the light red “Sp” with segmentation notations will give the word segmentation result. Conceptual Workflow of WS through Separation Inference. either adhesion (_Ad_) or separation (_Sp_). Therefore, we leverage bigram to adapt _\"Ad-Sp\"_ to describe the separation state of every two characters. _\"Ad-Sp\"_ eliminates the implied position restriction compared with existing tagging schemas. The separation state of the current bigram is not affected by the previous one. Meanwhile, there is no restriction on the first state in a sentence; it can be _Ad_ or _Sp_. Hence, our SpIn network can be built upon: (1) the bigram feature indicating the representation of two neighboring characters; (2) a classification network to explicitly learn the adhesion or separation state according to the current and all the other bigram features.