{"id":325971,"date":"2021-07-05T09:00:34","date_gmt":"2021-07-05T09:00:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=325971"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=325971","title":{"rendered":"\u041d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0432 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/084\/99d\/84e\/08499d84ec1d064f53821106e5f861e3.png\" width=\"623\" height=\"353\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438 \u2013 \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u043a \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0438 \u043f\u043e\u0438\u0441\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u041f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c, \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0442\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0443\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442. \u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u2013 \u044d\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u044b \u043a \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c. \u0427\u0442\u043e \u0436\u0435 \u0434\u043e \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0435\u0439, \u0442\u043e \u043e\u043d\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445, \u043d\u043e \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0435\u0439 (\u0420\u041d\u0421) \u0432 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 process mining.<\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0440\u0430\u0436\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0437\u0430\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0442\u043e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0441\u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0435\u0439. \u041a\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u043e\u0433\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u043b\u043e\u0433\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435. \u041d\u0430\u0448\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0446\u0435\u043b\u044c \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u043b\u043e\u0433\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432\u043e\u0437\u044c\u043c\u0451\u043c \u043b\u043e\u0433 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 L = [(a, b, c, d, e), (a, b, d)] \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0432\u0430 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u0430 \u00ab$\u00bb \u0438 \u00ab#\u00bb \u0432 \u043a\u0430\u0436\u0434\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e<\/p>\n<p>2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u043c \u0432\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u043c \u00ab#\u00bb, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0438\u043c\u0435\u043b\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0434\u043b\u0438\u043d\u0443<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c L \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 L \u0303 = [($, a, b, c, d, e, #), ($, a, b, d, #, #, #)] \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0434\u043b\u0438\u043d\u044b \u0432 7 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0442\u043e\u043a\u0435\u043d\u044b \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u043e\u0442 0 \u0434\u043e |\u0245|+1 (\u0433\u0434\u0435 |\u0245| &#8212; \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432)<\/p>\n<pre><code>\u041f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043b\u043e\u0433\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0432 pandas.DataFrame def preprocessing(df):         tracks = [list(track.sort_values(by=[\"timest\"], ascending=True).activity.values) for track_id, track in df.groupby(df.trace)]         tokens = sorted(list(set(df.activity)) +['#'])     token_to_id = {t:i for i,t in enumerate(tokens)}     id_to_token = {i:t for i,t in enumerate(tokens)}     MAX_LEN = max(list(map(len, tracks)))     tracks_ix = list(map(lambda track: list(map(token_to_id.get,track)), tracks))     for i in range(len(tracks_ix)):         if len(tracks_ix[i]) &lt; MAX_LEN:             tracks_ix[i] += [token_to_id['#']]*(MAX_LEN - len(tracks_ix[i]))     tracks_ix = np.array(tracks_ix)     return tokens, tracks_ix, id_to_token, token_to_id tokens, tracks_ix, id_to_token, token_to_id = preprocessing(df)     <\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043b\u043e\u0433\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d. \u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u0434\u043e\u043a\u0430\u0437\u0430\u0432\u0448\u0438\u0435 \u0441\u0432\u043e\u044e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 (\u0441\u043e\u0431\u044b\u0442\u0438\u044f) ai \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 ai+1, \u0442\u043e \u0435\u0441\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0438\u043c. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u0433\u0440\u0430\u0444\u0430 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c\u0438. \u0412\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0435\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440. \u0415\u0441\u043b\u0438 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u043f\u0440\u043e\u0433\u043d\u043e\u0437, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/13e\/91d\/e46\/13e91de46bb3a38c7383d9ecbe64742d.png\" width=\"623\" height=\"299\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0441\u043b\u043e\u0435 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u0446\u0435\u043b\u043e\u0435, \u043a\u043e\u0434\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0432\u0435\u043a\u0442\u043e\u0440 \u0442\u043e\u043a\u0435\u043d\u0430. \u0412\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0434\u043b\u044f \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u044d\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432: \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0438 \u0432\u0435\u043a\u0442\u043e\u0440 \u0442\u043e\u043a\u0435\u043d\u043e\u0432. \u0414\u0430\u043b\u0435\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u0441\u043b\u043e\u0439, \u0433\u0434\u0435 \u043a \u0432\u0435\u043a\u0442\u043e\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0443 \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u043c \u0441\u043b\u043e\u0435. \u041f\u0435\u0440\u0432\u044b\u0439 \u2013 \u044d\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440, \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0420\u041d\u0421 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u0435\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0413\u0443\u043c\u0431\u0435\u043b\u044c-\u0441\u0438\u0433\u043c\u043e\u0438\u0434\u0443, \u043a\u0430\u043a \u0434\u043e\u043a\u0430\u0437\u0430\u0432\u0448\u0443\u044e \u0441\u0432\u043e\u044e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0412\u0442\u043e\u0440\u043e\u0439 \u2013 \u0432\u0435\u043a\u0442\u043e\u0440 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 (\u0422\u0430\u0431\u043b\u0438\u0446\u0430 1). \u0414\u043b\u044f \u043d\u0435\u0433\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0441\u0438\u0433\u043c\u043e\u0438\u0434\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u043e\u0442\u0440\u0435\u0437\u043a\u0443 [0;1]. <\/p>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>$<\/p>\n<\/td>\n<td>\n<p>a<\/p>\n<\/td>\n<td>\n<p>\u2026<\/p>\n<\/td>\n<td>\n<p>#<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>0.215<\/p>\n<\/td>\n<td>\n<p>0.39<\/p>\n<\/td>\n<td>\n<p>\u2026<\/p>\n<\/td>\n<td>\n<p>0.12<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430 1. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043b\u043e\u0433\u0430 ~L<\/p>\n<pre><code>sequence = T.matrix('token sequence','int64')<\/code><\/pre>\n<pre><code>\u041d\u0430\u0441\u0442\u0440\u043e\u043a\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438: def model(tokens, token_to_id, neurons_num=5):     sequence = T.matrix('token sequence','int64')     inputs = sequence[:,:-1] # \u043f\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 - \u0432\u0441\u0435, \u043a\u0440\u043e\u043c\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e     targets = sequence[:,1:] # \u0430 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 - \u0432\u0441\u0435, \u043a\u0440\u043e\u043c\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e     l_input_sequence = InputLayer(shape=(None, None),input_var=inputs)     tau = theano.shared(np.float32(0.1))     pseudo_sigmoid = GumbelSigmoid(t=tau)     class step:             #inputs         h_prev = InputLayer((None, neurons_num),name='previous rnn state')         inp = InputLayer((None,),name='current character')         emb = EmbeddingLayer(inp, len(tokens), 30, name='emb') # \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430 \u0444\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c                  #recurrent part                          f_dense = DenseLayer(concat([h_prev, emb]), num_units=8, nonlinearity=T.nnet.relu)    # 0 .. +inf         s_dense = DenseLayer(f_dense, num_units=neurons_num, nonlinearity=None) # -inf .. +inf                  next_state_probs = NonlinearityLayer(s_dense, T.nnet.sigmoid) # \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0431\u0438\u0442\u043e\u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f         h_new = NonlinearityLayer(s_dense, pseudo_sigmoid) # \u041d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 - \u0432\u0435\u043a\u0442\u043e\u0440 \u0431\u0438\u0442\u043e\u0432          next_token_probas = DenseLayer(s_dense, len(tokens),nonlinearity=T.nnet.softmax) # \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u0430 - P(Ti|Ti-1....T0)     batch_size = sequence.shape[0]     initial_state = InputLayer((None, neurons_num), T.zeros((batch_size, neurons_num)))     training_loop = Recurrence(         state_variables={step.h_new:step.h_prev},         state_init={step.h_new:initial_state},         input_sequences={step.inp:l_input_sequence},         tracked_outputs=[step.next_token_probas,],         unroll_scan=False,     )       weights = lasagne.layers.get_all_params(training_loop, trainable=True)         predicted_probabilities = lasagne.layers.get_output(training_loop[step.next_token_probas])     xent = lasagne.objectives.categorical_crossentropy(predicted_probabilities.reshape((-1,len(tokens))),                                                    targets.reshape((-1,))).reshape(targets.shape)     mask = T.neq(inputs, token_to_id[\"#\"]) # \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b, \u0442.\u043a. \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u043f\u0430\u0434\u0434\u0438\u043d\u0433\u0430     loss = (mask * xent).sum(axis=1).mean() # \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438      #&lt;Loss function - a simple categorical crossentropy will do, maybe add some regularizer&gt;     updates = lasagne.updates.adam(loss, weights)     train_step = theano.function([sequence], loss,                              updates=training_loop.get_automatic_updates()+updates)          h_deterministic = NonlinearityLayer(step.next_state_probs, lambda x: T.gt(x, 0.5).astype(x.dtype))     validation_loop = Recurrence(         state_variables={h_deterministic:step.h_prev},         state_init={h_deterministic:initial_state},         input_sequences={step.inp:l_input_sequence},         tracked_outputs=[step.next_token_probas,],         unroll_scan=False,     )     states_seq = get_output(validation_loop[h_deterministic], {l_input_sequence:sequence})     infer_states = theano.function([sequence], states_seq, updates=None)     return train_step, infer_states<\/code><\/pre>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u043c <em>m<\/em> x <em>r<\/em> \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043f\u043e\u0442\u0435\u0440\u044c (\u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438), \u0433\u0434\u0435 <em>m<\/em> \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0432\u0445\u043e\u0434\u043d\u043e\u043c \u043b\u043e\u0433\u0435, \u0430 <em>r<\/em> \u2013 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043b\u043e\u0433\u0430, \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0442\u043e\u043a\u0435\u043d\u0443 (\u0441\u043e\u0431\u044b\u0442\u0438\u044e) \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044f <em>H(y^i, yi)<\/em>, \u0433\u0434\u0435 <em>y^i<\/em> \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u0430, \u0430 <em>yi \u2013 <\/em>\u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0438\u0437\u043b\u0438\u0448\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0447\u0435\u0439\u043a\u0438, \u0443\u043c\u043d\u043e\u0436\u0438\u0432 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043f\u043e\u0442\u0435\u0440\u044c \u043d\u0430 \u043c\u0430\u0441\u043a\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443. \u041c\u0430\u0441\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u2013 \u044d\u0442\u043e \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0441 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u043c\u0438 \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445 \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u00ab$\u00bb \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438 \u0438 \u043d\u0443\u043b\u044f\u043c\u0438 \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445 \u0441 \u00ab#\u00bb \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043e\u0442 \u0441\u0443\u043c\u043c \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 (\u0422\u0430\u0431\u043b\u0438\u0446\u0430 2)<\/p>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>$<\/p>\n<p>2.57<\/p>\n<\/td>\n<td>\n<p>a<\/p>\n<p>1.45<\/p>\n<\/td>\n<td>\n<p>b<\/p>\n<p>2.65<\/p>\n<\/td>\n<td>\n<p>c<\/p>\n<p>1.77<\/p>\n<\/td>\n<td>\n<p>d<\/p>\n<p>3.72<\/p>\n<\/td>\n<td>\n<p>e<\/p>\n<p>4.62<\/p>\n<\/td>\n<td>\n<p>#<\/p>\n<p>0<\/p>\n<\/td>\n<td>\n<p>&nbsp;<\/p>\n<p>16.78   <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>$<\/p>\n<p>2.57<\/p>\n<\/td>\n<td>\n<p>a<\/p>\n<p>1.45<\/p>\n<\/td>\n<td>\n<p>b<\/p>\n<p>2.65<\/p>\n<\/td>\n<td>\n<p>d<\/p>\n<p>2.51<\/p>\n<\/td>\n<td>\n<p>#<\/p>\n<p>0<\/p>\n<\/td>\n<td>\n<p>#<\/p>\n<p>0<\/p>\n<\/td>\n<td>\n<p>#<\/p>\n<p>0<\/p>\n<\/td>\n<td>\n<p>&nbsp;<\/p>\n<p>9.18   <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"7\">\n<p>\u0421\u0440\u0435\u0434\u043d\u0435\u0435<\/p>\n<\/td>\n<td>\n<p>12.98<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430 2. \u041c\u0430\u0442\u0440\u0438\u0446\u0430 \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438 \u043b\u043e\u0433\u0430 ~L<\/p>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043b\u043e\u0433\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430.<\/p>\n<pre><code>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438: def training(tokens, tracks_ix, token_to_id, neurons_num=5, n_epochs = 25, batches_per_epoch = 250, batch_size= 10):     train_step, infer_states = model(tokens,token_to_id)         for epoch in range(n_epochs):         avg_cost = 0;         for _ in range(batches_per_epoch):             avg_cost += train_step(sample_batch(tracks_ix, batch_size))         print(\"\\n\\nEpoch {} average loss = {}\".format(epoch, avg_cost \/ batches_per_epoch))     return infer_states infer_states = training(tokens, tracks_ix, token_to_id, 10)<\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 (TS) \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0441\u043e\u0431\u043e\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0434\u043b\u044f \u0420\u041d\u0421 \u0438 \u043d\u043e\u0432\u044b\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0449\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f TS. \u042d\u0442\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430\u043c\u0438, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u043f\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0442\u043e\u043a\u0435\u043d\u0443. <\/p>\n<pre><code>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 TS: def build_json(filename, inferred_states, tracks_ix, neurons_num=10):      graph = {\"states\":set(), \"transitions\":list(), \"meta\":{\"isAccepting\":set()}}     all_states = []     all_used_states = set()          for binary_states in inferred_states:         binary_states = np.vstack((np.zeros(neurons_num), binary_states)) # add initial state         states = list(map(binary_state_to_id, binary_states))         graph[\"states\"].update(set(states))         all_states.append(states)              for states, track_ids in zip(all_states, tracks_ix):         track = list(map(id_to_token.get, track_ids))         for index, symbol in enumerate(track):             transition = {\"from\":states[index], \"to\":states[index + 1], \"track\":symbol}             all_used_states.add(transition[\"from\"])             all_used_states.add(transition[\"to\"])             if transition not in graph[\"transitions\"]:                 graph[\"transitions\"].append(transition)           graph[\"meta\"][\"isAccepting\"].add(states[len(track)])              graph[\"states\"] = list(all_used_states)     graph[\"meta\"][\"isAccepting\"] = list(graph[\"meta\"][\"isAccepting\"])     graph[\"meta\"][\"tracksNum\"] = len(tracks_ix)     with open(filename, \"w\") as json_file:         json.dump(graph, json_file)     return graph inferred_states = infer_states(tracks_ix) graph = build_json(json_filename, inferred_states, tracks_ix)  \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u0433\u0440\u0430\u0444\u0430: def build_dot(json_graph, filename):     graph = \"digraph test {\\n\"     for state in json_graph[\"states\"]:         if state in json_graph[\"meta\"][\"isAccepting\"]:             graph += \"\\t\" + state + \" [shape=doublecircle];\\n\"         else:             graph += \"\\t\" + state + \";\\n\"     for transition in json_graph[\"transitions\"]:         graph += \"\\t\" + transition[\"from\"] + \" -&gt; \" + transition[\"to\"]          graph += \" [label=\\\"\" + transition[\"track\"] + \"\\\"];\\n\"     graph += \"}\"           with open(filename, \"w\") as graph_file:         print(graph, file=graph_file, end=\"\")     return graph dot_graph = build_dot(graph, dot_filename)<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9df\/da7\/9d6\/9dfda79d6c87fd3cbad14825f972cfc9.png\" width=\"117\" height=\"320\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043b\u043e\u0433\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u0430\u044e\u0442 \u043e\u0441\u043d\u043e\u0432\u0443 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0443\u0436\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u0434\u0448\u0438\u0445.<\/p>\n<p><a href=\"https:\/\/github.com\/nnetresearch\/nnet_pd\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 GitHub<\/a><\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/566114\/\"> https:\/\/habr.com\/ru\/post\/566114\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438 \u2013 \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u043a \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0438 \u043f\u043e\u0438\u0441\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u041f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c, \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0442\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0443\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442. \u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u2013 \u044d\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u044b \u043a \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c. \u0427\u0442\u043e \u0436\u0435 \u0434\u043e \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0435\u0439, \u0442\u043e \u043e\u043d\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445, \u043d\u043e \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0435\u0439 (\u0420\u041d\u0421) \u0432 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 process mining.<\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0440\u0430\u0436\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0437\u0430\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0442\u043e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0441\u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0435\u0439. \u041a\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u043e\u0433\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u043b\u043e\u0433\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435. \u041d\u0430\u0448\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0446\u0435\u043b\u044c \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u043b\u043e\u0433\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432\u043e\u0437\u044c\u043c\u0451\u043c \u043b\u043e\u0433 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 L = [(a, b, c, d, e), (a, b, d)] \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0432\u0430 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u0430 \u00ab$\u00bb \u0438 \u00ab#\u00bb \u0432 \u043a\u0430\u0436\u0434\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e<\/p>\n<p>2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u043c \u0432\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u043c \u00ab#\u00bb, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0438\u043c\u0435\u043b\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0434\u043b\u0438\u043d\u0443<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c L \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 L \u0303 = [($, a, b, c, d, e, #), ($, a, b, d, #, #, #)] \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0434\u043b\u0438\u043d\u044b \u0432 7 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0442\u043e\u043a\u0435\u043d\u044b \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u043e\u0442 0 \u0434\u043e |\u0245|+1 (\u0433\u0434\u0435 |\u0245| &#8212; \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432)<\/p>\n<pre><code>\u041f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043b\u043e\u0433\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0432 pandas.DataFrame def preprocessing(df):         tracks = [list(track.sort_values(by=[\"timest\"], ascending=True).activity.values) for track_id, track in df.groupby(df.trace)]         tokens = sorted(list(set(df.activity)) +['#'])     token_to_id = {t:i for i,t in enumerate(tokens)}     id_to_token = {i:t for i,t in enumerate(tokens)}     MAX_LEN = max(list(map(len, tracks)))     tracks_ix = list(map(lambda track: list(map(token_to_id.get,track)), tracks))     for i in range(len(tracks_ix)):         if len(tracks_ix[i]) &lt; MAX_LEN:             tracks_ix[i] += [token_to_id['#']]*(MAX_LEN - len(tracks_ix[i]))     tracks_ix = np.array(tracks_ix)     return tokens, tracks_ix, id_to_token, token_to_id tokens, tracks_ix, id_to_token, token_to_id = preprocessing(df)     <\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043b\u043e\u0433\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d. \u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u0434\u043e\u043a\u0430\u0437\u0430\u0432\u0448\u0438\u0435 \u0441\u0432\u043e\u044e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 (\u0441\u043e\u0431\u044b\u0442\u0438\u044f) ai \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 ai+1, \u0442\u043e \u0435\u0441\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0438\u043c. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u0433\u0440\u0430\u0444\u0430 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c\u0438. \u0412\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0435\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440. \u0415\u0441\u043b\u0438 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u043f\u0440\u043e\u0433\u043d\u043e\u0437, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0441\u043b\u043e\u0435 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u0446\u0435\u043b\u043e\u0435, \u043a\u043e\u0434\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0432\u0435\u043a\u0442\u043e\u0440 \u0442\u043e\u043a\u0435\u043d\u0430. \u0412\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0434\u043b\u044f \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u044d\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432: \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0438 \u0432\u0435\u043a\u0442\u043e\u0440 \u0442\u043e\u043a\u0435\u043d\u043e\u0432. \u0414\u0430\u043b\u0435\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u0441\u043b\u043e\u0439, \u0433\u0434\u0435 \u043a \u0432\u0435\u043a\u0442\u043e\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0443 \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u043c \u0441\u043b\u043e\u0435. \u041f\u0435\u0440\u0432\u044b\u0439 \u2013 \u044d\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440, \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0420\u041d\u0421 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u0435\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0413\u0443\u043c\u0431\u0435\u043b\u044c-\u0441\u0438\u0433\u043c\u043e\u0438\u0434\u0443, \u043a\u0430\u043a \u0434\u043e\u043a\u0430\u0437\u0430\u0432\u0448\u0443\u044e \u0441\u0432\u043e\u044e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0412\u0442\u043e\u0440\u043e\u0439 \u2013 \u0432\u0435\u043a\u0442\u043e\u0440 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 (\u0422\u0430\u0431\u043b\u0438\u0446\u0430 1). \u0414\u043b\u044f \u043d\u0435\u0433\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0441\u0438\u0433\u043c\u043e\u0438\u0434\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u043e\u0442\u0440\u0435\u0437\u043a\u0443 [0;1]. <\/p>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>$<\/p>\n<\/td>\n<td>\n<p>a<\/p>\n<\/td>\n<td>\n<p>\u2026<\/p>\n<\/td>\n<td>\n<p>#<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>0.215<\/p>\n<\/td>\n<td>\n<p>0.39<\/p>\n<\/td>\n<td>\n<p>\u2026<\/p>\n<\/td>\n<td>\n<p>0.12<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430 1. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043b\u043e\u0433\u0430 ~L<\/p>\n<pre><code>sequence = T.matrix('token sequence','int64')<\/code><\/pre>\n<pre><code>\u041d\u0430\u0441\u0442\u0440\u043e\u043a\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438: def model(tokens, token_to_id, neurons_num=5):     sequence = T.matrix('token sequence','int64')     inputs = sequence[:,:-1] # \u043f\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 - \u0432\u0441\u0435, \u043a\u0440\u043e\u043c\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e     targets = sequence[:,1:] # \u0430 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 - \u0432\u0441\u0435, \u043a\u0440\u043e\u043c\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e     l_input_sequence = InputLayer(shape=(None, None),input_var=inputs)     tau = theano.shared(np.float32(0.1))     pseudo_sigmoid = GumbelSigmoid(t=tau)     class step:             #inputs         h_prev = InputLayer((None, neurons_num),name='previous rnn state')         inp = InputLayer((None,),name='current character')         emb = EmbeddingLayer(inp, len(tokens), 30, name='emb') # \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430 \u0444\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c                  #recurrent part                          f_dense = DenseLayer(concat([h_prev, emb]), num_units=8, nonlinearity=T.nnet.relu)    # 0 .. +inf         s_dense = DenseLayer(f_dense, num_units=neurons_num, nonlinearity=None) # -inf .. +inf                  next_state_probs = NonlinearityLayer(s_dense, T.nnet.sigmoid) # \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0431\u0438\u0442\u043e\u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f         h_new = NonlinearityLayer(s_dense, pseudo_sigmoid) # \u041d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 - \u0432\u0435\u043a\u0442\u043e\u0440 \u0431\u0438\u0442\u043e\u0432          next_token_probas = DenseLayer(s_dense, len(tokens),nonlinearity=T.nnet.softmax) # \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u0430 - P(Ti|Ti-1....T0)     batch_size = sequence.shape[0]     initial_state = InputLayer((None, neurons_num), T.zeros((batch_size, neurons_num)))     training_loop = Recurrence(         state_variables={step.h_new:step.h_prev},         state_init={step.h_new:initial_state},         input_sequences={step.inp:l_input_sequence},         tracked_outputs=[step.next_token_probas,],         unroll_scan=False,     )       weights = lasagne.layers.get_all_params(training_loop, trainable=True)         predicted_probabilities = lasagne.layers.get_output(training_loop[step.next_token_probas])     xent = lasagne.objectives.categorical_crossentropy(predicted_probabilities.reshape((-1,len(tokens))),                                                    targets.reshape((-1,))).reshape(targets.shape)     mask = T.neq(inputs, token_to_id[\"#\"]) # \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b, \u0442.\u043a. \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u043f\u0430\u0434\u0434\u0438\u043d\u0433\u0430     loss = (mask * xent).sum(axis=1).mean() # \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438      #&lt;Loss function - a simple categorical crossentropy will do, maybe add some regularizer&gt;     updates = lasagne.updates.adam(loss, weights)     train_step = theano.function([sequence], loss,                              updates=training_loop.get_automatic_updates()+updates)          h_deterministic = NonlinearityLayer(step.next_state_probs, lambda x: T.gt(x, 0.5).astype(x.dtype))     validation_loop = Recurrence(         state_variables={h_deterministic:step.h_prev},         state_init={h_deterministic:initial_state},         input_sequences={step.inp:l_input_sequence},         tracked_outputs=[step.next_token_probas,],         unroll_scan=False,     )     states_seq = get_output(validation_loop[h_deterministic], {l_input_sequence:sequence})     infer_states = theano.function([sequence], states_seq, updates=None)     return train_step, infer_states<\/code><\/pre>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u043c <em>m<\/em> x <em>r<\/em> \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043f\u043e\u0442\u0435\u0440\u044c (\u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438), \u0433\u0434\u0435 <em>m<\/em> \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0432\u0445\u043e\u0434\u043d\u043e\u043c \u043b\u043e\u0433\u0435, \u0430 <em>r<\/em> \u2013 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043b\u043e\u0433\u0430, \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0442\u043e\u043a\u0435\u043d\u0443 (\u0441\u043e\u0431\u044b\u0442\u0438\u044e) \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044f <em>H(y^i, yi)<\/em>, \u0433\u0434\u0435 <em>y^i<\/em> \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u0430, \u0430 <em>yi \u2013 <\/em>\u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0438\u0437\u043b\u0438\u0448\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0447\u0435\u0439\u043a\u0438, \u0443\u043c\u043d\u043e\u0436\u0438\u0432 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043f\u043e\u0442\u0435\u0440\u044c \u043d\u0430 \u043c\u0430\u0441\u043a\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443. \u041c\u0430\u0441\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u2013 \u044d\u0442\u043e \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0441 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u043c\u0438 \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445 \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u00ab$\u00bb \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438 \u0438 \u043d\u0443\u043b\u044f\u043c\u0438 \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445 \u0441 \u00ab#\u00bb \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043e\u0442 \u0441\u0443\u043c\u043c \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 (\u0422\u0430\u0431\u043b\u0438\u0446\u0430 2)<\/p>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>$<\/p>\n<p>2.57<\/p>\n<\/td>\n<td>\n<p>a<\/p>\n<p>1.45<\/p>\n<\/td>\n<td>\n<p>b<\/p>\n<p>2.65<\/p>\n<\/td>\n<td>\n<p>c<\/p>\n<p>1.77<\/p>\n<\/td>\n<td>\n<p>d<\/p>\n<p>3.72<\/p>\n<\/td>\n<td>\n<p>e<\/p>\n<p>4.62<\/p>\n<\/td>\n<td>\n<p>#<\/p>\n<p>0<\/p>\n<\/td>\n<td>\n<p>&nbsp;<\/p>\n<p>16.78   <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>$<\/p>\n<p>2.57<\/p>\n<\/td>\n<td>\n<p>a<\/p>\n<p>1.45<\/p>\n<\/td>\n<td>\n<p>b<\/p>\n<p>2.65<\/p>\n<\/td>\n<td>\n<p>d<\/p>\n<p>2.51<\/p>\n<\/td>\n<td>\n<p>#<\/p>\n<p>0<\/p>\n<\/td>\n<td>\n<p>#<\/p>\n<p>0<\/p>\n<\/td>\n<td>\n<p>#<\/p>\n<p>0<\/p>\n<\/td>\n<td>\n<p>&nbsp;<\/p>\n<p>9.18   <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"7\">\n<p>\u0421\u0440\u0435\u0434\u043d\u0435\u0435<\/p>\n<\/td>\n<td>\n<p>12.98<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430 2. \u041c\u0430\u0442\u0440\u0438\u0446\u0430 \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438 \u043b\u043e\u0433\u0430 ~L<\/p>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043b\u043e\u0433\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430.<\/p>\n<pre><code>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438: def training(tokens, tracks_ix, token_to_id, neurons_num=5, n_epochs = 25, batches_per_epoch = 250, batch_size= 10):     train_step, infer_states = model(tokens,token_to_id)         for epoch in range(n_epochs):         avg_cost = 0;         for _ in range(batches_per_epoch):             avg_cost += train_step(sample_batch(tracks_ix, batch_size))         print(\"\\n\\nEpoch {} average loss = {}\".format(epoch, avg_cost \/ batches_per_epoch))     return<\/code><\/pre>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-325971","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325971","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=325971"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325971\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}