Spaces:
Sleeping
Sleeping
Piyushmryaa
commited on
Commit
•
cefdfe3
1
Parent(s):
6d752b4
updated sentence input change
Browse files
app.py
CHANGED
@@ -1,3 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# -*- coding: utf-8 -*-
|
2 |
"""usemodel.ipynb
|
3 |
|
@@ -68,16 +156,27 @@ def predictsentence(postagsOfSentence):
|
|
68 |
chunks.append(0)
|
69 |
return chunks
|
70 |
def input_(input):
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
st.title('Chunk tagging')
|
80 |
input = st.text_input('Input the pos tags')
|
|
|
|
|
|
|
|
|
81 |
inputs = input_(input)
|
82 |
output = predictsentence(inputs)
|
83 |
st.write(output)
|
|
|
1 |
+
# # -*- coding: utf-8 -*-
|
2 |
+
# """usemodel.ipynb
|
3 |
+
|
4 |
+
# Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
# Original file is located at
|
7 |
+
# https://colab.research.google.com/drive/1c8Qtf9TWr3apElEv2uDgCD_MQwHnmw0B
|
8 |
+
# """
|
9 |
+
|
10 |
+
# import pickle
|
11 |
+
# from mygrad import Neuron, Value
|
12 |
+
# import streamlit as st
|
13 |
+
# def convertToOneHotEncode(tags):
|
14 |
+
# tag1 = tags[0]
|
15 |
+
# tag2 = tags[1]
|
16 |
+
# vec1 = [0]*5
|
17 |
+
# vec2 = [0]*4
|
18 |
+
# vec1[tag1] = 1
|
19 |
+
# vec2[tag2-1] = 1
|
20 |
+
# vec1.extend(vec2)
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
# return vec1
|
25 |
+
# def loadModel():
|
26 |
+
# neuron1weightsbias = []
|
27 |
+
# with open(f'weights.pkl', 'rb') as file:
|
28 |
+
# neuron1weightsbias = pickle.load(file)
|
29 |
+
# neuron = Neuron(10)
|
30 |
+
|
31 |
+
# neuron.w = [Value(i) for i in neuron1weightsbias[:-1]]
|
32 |
+
# neuron.b = Value(neuron1weightsbias[-1])
|
33 |
+
# return neuron
|
34 |
+
|
35 |
+
# import json
|
36 |
+
# def loadjson(filepath):
|
37 |
+
# data = []
|
38 |
+
# with open(filepath, 'rb') as file:
|
39 |
+
# for line in file:
|
40 |
+
# data.append(json.loads(line))
|
41 |
+
# return data
|
42 |
+
|
43 |
+
# data = loadjson('data/train.jsonl')
|
44 |
+
# data2 = loadjson('data/test.jsonl')
|
45 |
+
# X = [element['pos_tags'] for element in data] + [element['pos_tags'] for element in data2]
|
46 |
+
# Y = [element['chunk_tags'] for element in data] + [element['chunk_tags'] for element in data2]
|
47 |
+
|
48 |
+
# n = loadModel()
|
49 |
+
|
50 |
+
# def predictsentence(postagsOfSentence):
|
51 |
+
# if postagsOfSentence:
|
52 |
+
# postagsOfSentence = [0] + postagsOfSentence
|
53 |
+
# else:
|
54 |
+
# return
|
55 |
+
# xnew = []
|
56 |
+
# for ix in range(1, len(postagsOfSentence)):
|
57 |
+
# xnew.append([ postagsOfSentence[ix-1], postagsOfSentence[ix]])
|
58 |
+
# for ix, pair in enumerate(xnew):
|
59 |
+
# xnew[ix] = convertToOneHotEncode(pair)
|
60 |
+
# w = Value(0)
|
61 |
+
# chunks = []
|
62 |
+
# for ix2, wordpair in enumerate(xnew):
|
63 |
+
# xinput = [w] + wordpair
|
64 |
+
# w = n(xinput)
|
65 |
+
# if w.data > 0.5:
|
66 |
+
# chunks.append(1)
|
67 |
+
# else:
|
68 |
+
# chunks.append(0)
|
69 |
+
# return chunks
|
70 |
+
# def input_(input):
|
71 |
+
# input = input.split(',')
|
72 |
+
# inputs = [int(x.strip()) for x in input]
|
73 |
+
# # for i in input:
|
74 |
+
# # if i.isalphanumeric():
|
75 |
+
# # inputs.append(int(input))
|
76 |
+
# # else:
|
77 |
+
# # st.write('Invalid Input')
|
78 |
+
# return inputs
|
79 |
+
# st.title('Chunk tagging')
|
80 |
+
# input = st.text_input('Input the pos tags')
|
81 |
+
# inputs = input_(input)
|
82 |
+
# output = predictsentence(inputs)
|
83 |
+
# st.write(output)
|
84 |
+
|
85 |
+
# # import pandas as pd
|
86 |
+
# # data = output
|
87 |
+
# # df = pd.DataFrame.from_dict(data)
|
88 |
+
# # st.dataframe(df)
|
89 |
# -*- coding: utf-8 -*-
|
90 |
"""usemodel.ipynb
|
91 |
|
|
|
156 |
chunks.append(0)
|
157 |
return chunks
|
158 |
def input_(input):
|
159 |
+
if not input:
|
160 |
+
return
|
161 |
+
result = word_tokenize(input)
|
162 |
+
word_pos= nltk.pos_tag(result)
|
163 |
+
pos = [ i[1] for i in word_pos]
|
164 |
+
for i in range(len(pos)):
|
165 |
+
if pos[i] =='NN':
|
166 |
+
pos[i] = 1
|
167 |
+
elif pos[i] =='DT':
|
168 |
+
pos[i] = 2
|
169 |
+
elif pos[i] =='JJ':
|
170 |
+
pos[i] = 3
|
171 |
+
else:
|
172 |
+
pos[i]= 4
|
173 |
+
return pos
|
174 |
st.title('Chunk tagging')
|
175 |
input = st.text_input('Input the pos tags')
|
176 |
+
|
177 |
+
import nltk
|
178 |
+
from nltk.tokenize import word_tokenize
|
179 |
+
|
180 |
inputs = input_(input)
|
181 |
output = predictsentence(inputs)
|
182 |
st.write(output)
|