EvaanCarloss commited on
Commit
25d904d
·
verified ·
1 Parent(s): db2b287

Upload folder using huggingface_hub

Browse files
Natural_Language_Processing_with_Disaster_Tweets.ipynb ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": [],
7
+ "authorship_tag": "ABX9TyOVeNzsdktxbRWVeOMtsvBq",
8
+ "include_colab_link": true
9
+ },
10
+ "kernelspec": {
11
+ "name": "python3",
12
+ "display_name": "Python 3"
13
+ },
14
+ "language_info": {
15
+ "name": "python"
16
+ }
17
+ },
18
+ "cells": [
19
+ {
20
+ "cell_type": "markdown",
21
+ "metadata": {
22
+ "id": "view-in-github",
23
+ "colab_type": "text"
24
+ },
25
+ "source": [
26
+ "<a href=\"https://colab.research.google.com/github/CarlosEduDev/Natural-Language-Processing-with-Disaster-Tweets/blob/main/Natural_Language_Processing_with_Disaster_Tweets.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "markdown",
31
+ "source": [
32
+ "# Natural Language Processing with Disaster Tweets"
33
+ ],
34
+ "metadata": {
35
+ "id": "MVogzeoOfuRi"
36
+ }
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "source": [
41
+ "import pandas as pd\n",
42
+ "import re\n",
43
+ "from sklearn.feature_extraction.text import TfidfVectorizer\n",
44
+ "from sklearn.linear_model import LogisticRegression\n",
45
+ "from sklearn.model_selection import cross_val_score"
46
+ ],
47
+ "metadata": {
48
+ "id": "HrR8W4Mvf9Mg"
49
+ },
50
+ "execution_count": 148,
51
+ "outputs": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "source": [
56
+ "train_df = pd.read_csv('train.csv')\n",
57
+ "test_df = pd.read_csv('test.csv')"
58
+ ],
59
+ "metadata": {
60
+ "id": "IrbdmTVegEpC"
61
+ },
62
+ "execution_count": 149,
63
+ "outputs": []
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "source": [
68
+ "def clean_text(text):\n",
69
+ " text = text.lower()\n",
70
+ " text = re.sub(r'https?://\\S+|www\\.\\S+', '', text) # Remove URLs\n",
71
+ " text = re.sub(r'<.*?>+', '', text) # Remove tags HTML\n",
72
+ " text = re.sub(r'[^a-zA-Z0-9\\s]', '', text) # Mantem apenas letras e espacos\n",
73
+ " return text\n",
74
+ "\n",
75
+ "train_df['text_clean'] = train_df['text'].apply(clean_text)\n",
76
+ "test_df['text_clean'] = test_df['text'].apply(clean_text)"
77
+ ],
78
+ "metadata": {
79
+ "id": "E10M6M8xhSgZ"
80
+ },
81
+ "execution_count": 150,
82
+ "outputs": []
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "source": [
87
+ "vectorizer = TfidfVectorizer(max_features=10000, ngram_range=(1, 2), sublinear_tf=True)\n",
88
+ "X_train = vectorizer.fit_transform(train_df['text_clean'])\n",
89
+ "y_train = train_df['target']"
90
+ ],
91
+ "metadata": {
92
+ "id": "HwQCivCjDv4r"
93
+ },
94
+ "execution_count": 151,
95
+ "outputs": []
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "source": [
100
+ "# treinamento e avaliação inicial (validação cruzada)\n",
101
+ "model = LogisticRegression(C = 1.0, max_iter = 5000)\n",
102
+ "scores = cross_val_score(model, X_train, y_train, cv = 5, scoring = 'f1')\n",
103
+ "\n",
104
+ "print(f\"F1-Score médio na avaliação cruzada {scores.mean():.4f}\")"
105
+ ],
106
+ "metadata": {
107
+ "colab": {
108
+ "base_uri": "https://localhost:8080/"
109
+ },
110
+ "id": "HUHOHxod_MVQ",
111
+ "outputId": "c31bf8cb-5815-46fb-8b59-1a644391a1ef"
112
+ },
113
+ "execution_count": 152,
114
+ "outputs": [
115
+ {
116
+ "output_type": "stream",
117
+ "name": "stdout",
118
+ "text": [
119
+ "F1-Score médio na avaliação cruzada 0.6228\n"
120
+ ]
121
+ }
122
+ ]
123
+ },
124
+ {
125
+ "cell_type": "code",
126
+ "source": [
127
+ "# Treinamento com a base completa e geracao do arquivo de submissao\n",
128
+ "model.fit(X_train, y_train)\n",
129
+ "prediction = model.predict(X_test)\n",
130
+ "\n",
131
+ "submission = pd.DataFrame({\n",
132
+ " 'id': test_df['id'],\n",
133
+ " 'target': prediction\n",
134
+ " })\n",
135
+ "\n",
136
+ "submission.to_csv(\"submission_baseline.csv\", index = False)"
137
+ ],
138
+ "metadata": {
139
+ "id": "X3YF52V1_xkC"
140
+ },
141
+ "execution_count": 153,
142
+ "outputs": []
143
+ }
144
+ ]
145
+ }
README.md ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚨 Natural Language Processing with Disaster Tweets
2
+
3
+ Este repositório contém uma solução para a competição **"Natural Language Processing with Disaster Tweets"** do Kaggle. O objetivo do projeto é construir um modelo de Machine Learning/Deep Learning capaz de classificar se um tweet está relatando um desastre/emergência real (`1`) ou se utiliza termos conotativos/figurados (`0`).
4
+
5
+ ---
6
+
7
+ ## 📌 Visão Geral do Projeto
8
+
9
+ - **Plataforma:** Kaggle
10
+ - **Métrica de Avaliação:** $F_1\text{-score}$
11
+ - **Linguagem:** Python 3.x
12
+ - **Principais Tecnologias:** `pandas`, `scikit-learn`, `PyTorch`, `transformers` (Hugging Face)
13
+
14
+ ---
15
+
16
+ ## ⚙️ Abordagem e Modelos
17
+
18
+ ### Baseline: TF-IDF + Logistic Regression
19
+ - **Pré-processamento:** Limpeza de URLs e tags HTML, preservação de hashtags e números, e concatenação do campo `keyword` ao texto do tweet.
20
+ - **Vetorização:** `TfidfVectorizer` (unigramas e bigramas, `max_features=10000`).
21
+ - **Algoritmo:** Regressão Logística.
22
+ - **Resultado ($F_1\text{-score}$ em Validação Cruzada 5-Fold):** ~0.785
23
+
24
+ ---
25
+
26
+ ## 📂 Estrutura do Repositório
27
+
28
+ ```text
29
+ ├── data/
30
+ │ ├── train.csv # Dataset de treino
31
+ │ └── test.csv # Dataset de teste (Kaggle)
32
+ ├── notebooks/
33
+ │ ├── 01_baseline_tfidf.ipynb # Modelo baseline (TF-IDF + Logistic Regression)
34
+ ├── submissions/
35
+ │ ├── submission_baseline.csv
36
+ │ └── submission_deberta.csv
37
+ ├── README.md
38
+ └── requirements.txt