<jupyter_start><jupyter_text>Python dilinde Yapay Sinir Ağları (YSA) Modellemesi<NAME> Ar-Ge Ekip Lideri, SestekProblem:Chatbot'a şöyle içerik geldiğinde bunu nasıl anlaşılır formata dönüştürürüz?"faturabilgisi öğrenmek istiyorum"  İleri beslemeli YSA![feedforward_nnet](feedforward_nnet.png)ref: https://cdn-images-1.medium.com/max/800/1*pbk9xtz7WbBwYPVATdl9Vw.png Gereklilikler:* [miniconda](https://docs.conda.io/en/latest/miniconda.html) kurulur.* Miniconda kurulumu sırasında Path'e ekle opsiyonu seçilir.* cmd```consoleconda update condaconda install python=3.6pip install numpypip install cntk / pip install cntk-gpupip install tensorboardpip install tensorflow``` ```pythonali okula gitti 	 	 	 	 	{a}	l	i	o	k	u	1 	 	 	 	a	{l}	i	o	k	u	l	1 	 	 	a	l	{i}	o	k	u	l	a	0 	a	l	i	 	{o}	k	u	l	a	g	1a	l	i	 	o	{k}	u	l	a	g	i	1l	i	 	o	k	{u}	l	a	g	i	t	1i	 	o	k	u	{l}	a	g	i	t	t	1 	o	k	u	l	{a}	g	i	t	t	i	0k	u	l	a	 	{g}	i	t	t	i	h	1u	l	a	 	g	{i}	t	t	i	h	a	1l	a	 	g	i	{t}	t	i	h	a	s	1a	 	g	i	t	{t}	i	h	a	s	a	1 	g	i	t	t	{i}	h	a	s	a	n	0```<jupyter_code>import io
import re
import numpy as np


tr_upper = list(" ABC<KEY>")
tr_lower = list(" abcçdefgğhıijklmnoöprsştuüvyz")
left_context = 9
right_context = 9
def line_to_seq(line):
    seq = []
    for ch in line:
        if ch in tr_lower:
            seq.append(tr_lower.index(ch))
        elif ch in tr_upper:
            seq.append(tr_upper.index(ch))
        else:
            seq.append(tr_lower.index(' '))
    return seq
def add_context(items, index):
        items_count = len(items)

        go_back = []
        found_count = 0
        cursor = index
        while True:
            if left_context == 0:
                break
            target = 0
            cursor -= 1
            if cursor >= 0:
                target = items[cursor]

            go_back.append(target)
            found_count += 1
            if found_count >= left_context:
                break

        go_forward = []
        found_count = 0
        cursor = index
        while True:
            if right_context == 0:
                break
            target = 0
            cursor += 1
            if cursor < items_count:
                target = items[cursor]

            if cursor < items_count and target == 0:
                continue

            go_forward.append(target)
            found_count += 1
            if found_count >= right_context:
                break

        prev_items = list(reversed(go_back))

        return prev_items + [items[index]] + go_forward
def prepare_ctf_data(data_file, ctf_file):
    with io.open(data_file, mode='rt', encoding='utf-8') as fr:
        lines = fr.read().splitlines()

    zero_sample_count = 0
    one_sample_count = 0
    with open(ctf_file, mode="wt", encoding="utf-8") as fw:
        for line in lines:
            normalized_line = re.sub(r'\s+', ' ', line)
            normalized_line = normalized_line.strip() + ' '
            seq = line_to_seq(normalized_line)

            for i in range(len(seq) - 1):
                next_item = seq[i + 1]
                label = 0 if (next_item == 0) else 1
                feat = np.array(add_context(seq, i)) / len(tr_upper)

                if label == 1:
                    one_sample_count += 1
                else:
                    zero_sample_count += 1

                label_str = "0 1" if label == 1 else "1 0"
                feature_str = " ".join(["{:.6f}".format(k) for k in feat])
                line = "|labels {} |features {}\n".format(label_str, feature_str)
                fw.write(line)

    print("one_sample_count: {} zero_sample_count: {}".format(one_sample_count, zero_sample_count))

prepare_ctf_data("validation.txt", "validation.ctf")
prepare_ctf_data("train.txt", "train.ctf")
prepare_ctf_data("train_subset.txt", "train_subset.ctf")<jupyter_output>one_sample_count: 68542 zero_sample_count: 13306
{'fraction_non_alphanumeric': 0.10222567287784678, 'fraction_numerical': 0.016821946169772256, 'mean_word_length': 2.0171740827478533, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '502474', 'license': 'MIT', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1452, 'n_words': 383, 'path': '2019-03-02-Boun-TechSummit-Chatbot/src/neural_networks/space_detection_demo.ipynb', 'repo_name': 'sestek/presentations', 'size': '3895'}