{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":121150,"databundleVersionId":14976537,"sourceType":"competition"}],"dockerImageVersionId":31234,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-12-18T04:17:14.780940Z","iopub.execute_input":"2025-12-18T04:17:14.781307Z","iopub.status.idle":"2025-12-18T04:17:14.789645Z","shell.execute_reply.started":"2025-12-18T04:17:14.781281Z","shell.execute_reply":"2025-12-18T04:17:14.788688Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport tensorflow as tf\nfrom tensorflow.keras import layers, models, optimizers\nimport os, re\n\n# 1. డేటాను వెతికి లోడ్ చేయడం (FileNotFoundError రాకుండా)\ntrain_path = \"\"\ntest_path = \"\"\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        if 'train' in filename.lower(): train_path = os.path.join(dirname, filename)\n        if 'test' in filename.lower(): test_path = os.path.join(dirname, filename)\n\nif not train_path or not test_path:\n    print(\"Error: Files not found! దయచేసి డేటాసెట్ యాడ్ అయిందో లేదో చూడండి.\")\nelse:\n    train_df = pd.read_csv(train_path)\n    test_df = pd.read_csv(test_path)\n    print(\"Files Loaded Successfully!\")\n\n    # 2. డేటా క్లీనింగ్\n    def clean(text):\n        text = str(text).lower()\n        return re.sub(r'[^a-z0-9\\s]', '', text).strip()\n\n    train_df['clean_in'] = train_df.iloc[:, 1].apply(clean)\n    train_df['clean_out'] = train_df.iloc[:, 2].apply(clean)\n\n    # 3. టోకనైజేషన్\n    max_len = 80\n    tok_in = tf.keras.preprocessing.text.Tokenizer(filters='')\n    tok_in.fit_on_texts(train_df['clean_in'])\n    X = tf.keras.preprocessing.sequence.pad_sequences(tok_in.texts_to_sequences(train_df['clean_in']), maxlen=max_len, padding='post')\n\n    tok_out = tf.keras.preprocessing.text.Tokenizer(filters='')\n    tok_out.fit_on_texts(train_df['clean_out'])\n    y = tf.keras.preprocessing.sequence.pad_sequences(tok_out.texts_to_sequences(train_df['clean_out']), maxlen=max_len, padding='post')\n\n    # 4. పవర్‌ఫుల్ BiLSTM మోడల్\n    model = models.Sequential([\n        layers.Embedding(len(tok_in.word_index)+1, 512, input_length=max_len),\n        layers.Bidirectional(layers.LSTM(512, return_sequences=True)),\n        layers.Bidirectional(layers.LSTM(256, return_sequences=True)),\n        layers.TimeDistributed(layers.Dense(len(tok_out.word_index)+1, activation='softmax'))\n    ])\n\n    model.compile(optimizer=optimizers.Adam(0.001), loss='sparse_categorical_crossentropy')\n\n    # 5. ట్రైనింగ్ (300 Epochs)\n    print(\"Training Started... దయచేసి వేచి ఉండండి.\")\n    model.fit(X, y.reshape(y.shape[0], y.shape[1], 1), epochs=300, batch_size=64, verbose=1)\n\n    # 6. ప్రెడిక్షన్ & సబ్మిషన్ ఫైల్\n    results = []\n    test_clean = test_df.iloc[:, 0].apply(clean)\n    for sentence in test_clean:\n        seq = tok_in.texts_to_sequences([sentence])\n        padded = tf.keras.preprocessing.sequence.pad_sequences(seq, maxlen=max_len, padding='post')\n        pred = model.predict(padded, verbose=0)\n        words = [tok_out.index_word[idx] for idx in [np.argmax(p) for p in pred[0]] if idx > 0 and idx in tok_out.index_word]\n        results.append(' '.join(words) if words else \"the\")\n\n    submission = pd.DataFrame({'id': test_df.iloc[:, 0], 'translation': results})\n    submission.to_csv('submission.csv', index=False)\n    print(\"Success! 'submission.csv' ఫైల్ తయారైంది.\")\n    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-22T05:00:15.511058Z","iopub.execute_input":"2025-12-22T05:00:15.511649Z","iopub.status.idle":"2025-12-22T05:15:42.033640Z","shell.execute_reply.started":"2025-12-22T05:00:15.511611Z","shell.execute_reply":"2025-12-22T05:15:42.032932Z"}},"outputs":[],"execution_count":null}]}