File size: 3,508 Bytes
dd56b45
 
 
fdf758a
 
 
613fbdc
 
c420072
613fbdc
7695b3e
c420072
fdf758a
 
 
 
 
 
dd56b45
fdf758a
 
dd56b45
fdf758a
 
 
613fbdc
 
 
 
 
 
 
 
fdf758a
 
613fbdc
 
 
 
 
 
 
 
fdf758a
c420072
fdf758a
dd56b45
 
fdf758a
 
 
dd56b45
fdf758a
613fbdc
dd56b45
fdf758a
 
dd56b45
fdf758a
 
dd56b45
fdf758a
 
 
 
 
 
 
 
 
 
 
613fbdc
dd56b45
fdf758a
 
dd56b45
fdf758a
 
 
 
 
 
 
 
 
 
 
 
613fbdc
fdf758a
 
613fbdc
fdf758a
613fbdc
fdf758a
 
 
 
 
 
 
 
 
dd56b45
fdf758a
 
dd56b45
fdf758a
 
 
 
 
 
 
 
613fbdc
dd56b45
613fbdc
 
dd56b45
 
 
613fbdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import numpy as np
import streamlit as st
import nltk
from nltk.tokenize import word_tokenize

# Load your image files
demo_image_path = "demo.jpeg"
gif_image_path = "1.gif"

# Display demo image
st.image(demo_image_path, use_column_width=True)

# Load your neural network weights and biases
wei_prev = [6.53372226, 1.45266998, -1.31130261, -3.16864773, 0.39603089]
wei_cur = [1.74665619, -0.74696832, 2.84321548, -1.33783743]
wei_fb = [1.28461033]
wei_bias = [0.41829136]

def sigmoid(x):
    return 1 / (1 + np.exp(-x))

def sigmoid_derivative(x):
    return x * (1 - x)

def onehot_pos_cur(num):
    if num == 1:
        return np.array([0, 0, 0, 1])
    if num == 2:
        return np.array([0, 0, 1, 0])
    if num == 3:
        return np.array([0, 1, 0,iadsl 0])
    if num == 4:
        return np.array([1, 0, 0, 0])

def onehot_pos_prev(num):
    if num == 1:
        return np.array([0, 0, 0, 0, 1])
    if num == 2:
        return np.array([0, 0, 0, 1, 0])
    if num == 3:
        return np.array([0, 0, 1, 0, 0])
    if num == 4:
        return np.array([0, 1, 0, 0, 0])

st.title("🌲 Recurrent Perceptron for Noun Chunk Identification 🌲")

# Using Markdown for the input text to include an emoji
user_input = st.text_input("Enter a POS tagged input", "")

tokens = word_tokenize(user_input)

# Perform part-of-speech tagging
tagged_words = nltk.pos_tag(tokens)

# Define the tags of interest
tags_of_interest = ['NN', 'DT', 'JJ', 'NNS']

# Initialize a list to store filtered words
filtered_words = []

# Filter tagged words based on tags of interest
for word, tag in tagged_words:
    if tag=='NN' or tag=='NNS' or tag=='NNP' or tag=='NNPS':
        filtered_words.append(1)
    elif tag=='DT' or tag=='PDT' or tag=='POS':
        filtered_words.append(2)
    elif tag=='JJ' or tag=='JJR' or tag=='JJS':
        filtered_words.append(3)
    else:
        filtered_words.append(4)

user_input = filtered_words

# Display the "Classify" button with larger size
classify_button = st.button(" Classify ", key="classify_button", help="Click to classify")

# Adjusting the size of the classify button using CSS
st.markdown(
    """
    <style>
    .stButton>button {
        width: 200px !important;
        height: 50px !important;
        font-size: 18px !important;
    }
    </style>
    """,
    unsafe_allow_html=True
)

output = []
if classify_button:
    user_input = np.array(list(user_input), dtype=int)
  
    for i in range(len(user_input)):
        if i == 0:
            x_prev = np.array([1, 0, 0, 0, 0])  # Initial previous POS tag (V)
            y_prev = 0  # Initial previous output
        else:
            x_prev = onehot_pos_prev(x_prev)  # Convert previous POS tag to one-hot vector

        x_cur_int = user_input[i]  # Current POS tag index
        x_cur = onehot_pos_cur(x_cur_int)  # Convert current POS tag to one-hot vector

        # Forward pass through the network using sigmoid activation function
        y_cur = sigmoid((np.dot(wei_fb, y_prev) + np.dot(wei_prev, x_prev) + np.dot(wei_cur, x_cur) - wei_bias).item())

        # Predict the label based on the output of the network
        if y_cur > 0.5:
            output.append(1)
        else:
            output.append(0)

        x_prev = x_cur_int
        y_prev = y_cur

    st.write(output)

# Display 1.gif image
st.image(gif_image_path, use_column_width=True)

# Add the message below the Classify button
st.markdown("• **Made by 4 IIT-Bombay students.**")
st.markdown("• **Hosted by ❤️**")