- Machine Learning for Cybersecurity Cookbook
- Emmanuel Tsukerman
- 289字
- 2021-06-24 12:28:57
How it works...
We begin the recipe by importing the Markovify library, a library for Markov chain computations, and reading in text, which will inform our Markov model (step 1). In step 2, we create a Markov chain model using the text. The following is a relevant snippet from the text object's initialization code:
class Text(object):
reject_pat = re.compile(r"(^')|('$)|\s'|'\s|[\"(\(\)\[\])]")
def __init__(self, input_text, state_size=2, chain=None, parsed_sentences=None, retain_original=True, well_formed=True, reject_reg=''):
"""
input_text: A string.
state_size: An integer, indicating the number of words in the model's state.
chain: A trained markovify.Chain instance for this text, if pre-processed.
parsed_sentences: A list of lists, where each outer list is a "run"
of the process (e.g. a single sentence), and each inner list
contains the steps (e.g. words) in the run. If you want to simulate
an infinite process, you can come very close by passing just one, very
long run.
retain_original: Indicates whether to keep the original corpus.
well_formed: Indicates whether sentences should be well-formed, preventing
unmatched quotes, parenthesis by default, or a custom regular expression
can be provided.
reject_reg: If well_formed is True, this can be provided to override the
standard rejection pattern.
"""
The most important parameter to understand is state_size = 2, which means that the Markov chains will be computing transitions between consecutive pairs of words. For more realistic sentences, this parameter can be increased, at the cost of making sentences appear less original. Next, we apply the Markov chains we have trained to generate a few example sentences (steps 3 and 4). We can see clearly that the Markov chains have captured the tone and style of the text. Finally, in step 5, we create a few tweets in the style of the airport reviews using our Markov chains.
- 數(shù)據(jù)展現(xiàn)的藝術(shù)
- Mastering Matplotlib 2.x
- OpenStack for Architects
- 協(xié)作機器人技術(shù)及應(yīng)用
- 手把手教你玩轉(zhuǎn)RPA:基于UiPath和Blue Prism
- 自動控制原理
- ServiceNow Cookbook
- 大學計算機應(yīng)用基礎(chǔ)
- Learn CloudFormation
- TensorFlow Reinforcement Learning Quick Start Guide
- Excel 2007常見技法與行業(yè)應(yīng)用實例精講
- Visual C++項目開發(fā)案例精粹
- 液壓機智能故障診斷方法集成技術(shù)
- 寒江獨釣:Windows內(nèi)核安全編程
- 大數(shù)據(jù)素質(zhì)讀本