Preliminary Design for Teaching Latin and Artificial Intelligence
1. Stage One: Linguistics and Neuroscience Teach the students the idea of a sentence and also the idea of a neuronal structure that generates a sentence. 2. Stage Two: Introduce a Particular Programming Language Use PYTHON as a major AI language, or possibly use tutorial JavaScript as a teaching language, since the Mens Latina AI already exists in JavaScript for Microsoft Internet Explorer. Possibly poll the students to see if significant numbers of students already know a particular coding language or are learning such a language. If the host institution uses a particular programming language like Python to introduce computer programming to students in general, then perhaps use the same coding language for teaching Latin AI. 3. Stage Three: Teach Vocabulary as an Array of Concepts 4. Stage Four: Teach Pronunciation as an Array of Phonemic Words 5. Stage Five: Teach Noun-Declension and the Noun-Phrase Mind-Module 6. Stage Six: Teach Verb-Conjugation and the Verb-Phrase Mind-Module 7. Stage Seven: Teach Moods Indicative, Imperative, Interrogative, Subjunctive 8. Stage Eight: Teach Volition Mind-Module as Invoker of Imperative Mood Divide free will or volition into its thinking component and its emotional component. 9. Stage Nine: Teach Thinking as Divisible into Statements and Inferences 10. Stage Ten: Teach Conjunctions as Vocabulary for ConJoin Module 11. Stage Eleven: Teach Prepositions as Vocabulary for LaPrep Module 12. Stage Twelve: Publish a Joint Latin and AI Textbook Embed the AI material in such a way that a teacher wishing to teach only the Latin may skip the AI material about neuroscience and programming and natural language processing (NLP). http://ai.neocities.org/LaThink.html -- Latin AI Thinking Module. #LatinAI #AI4U #AiGuarantee #AiHasBeenSolved #Python -- https://mail.python.org/mailman/listinfo/python-list
Re: How to handle async and inheritance?
Stephen Rosen wrote at 2020-6-30 11:59 -0400: >Hi all, > >I'm looking at a conflict between code sharing via inheritance and async >usage. I would greatly appreciate any guidance, ideas, or best practices >which might help. > >I'll speak here in terms of a toy example, but, if anyone wants to look at >the real code, I'm working on webargs. [1] Specifically, we have a `Parser` >class and an `AsyncParser` subclass, and the two have a lot of code >duplication to handle async/await. [2] > > >I've got an inheritance structure like this: > >class MyAbstractType: ... >class ConcreteType(MyAbstractType): ... >class AsyncConcreteType(MyAbstractType): ... > >One of my goals, of course, is to share code between ConcreteType and >AsyncConcreteType via their parent. >But the trouble is that there are functions defined like this: > >class MyAbstractType: >def foo(self): >x = self.bar() >y = self.baz(x) >... # some code here, let's say 20 lines > >class AsyncConcreteType(MyAbstractType): >async def foo(self): >x = await self.bar() >y = self.baz(x) >... # the same 20 lines as above, but with an `await` added >every-other line > > >I'm aware that I'm looking at "function color" and that my scenario is >pitting two language features -- inheritance and async -- against one >another. But I don't see a clean way out if we want to support an >"async-aware" version of a class with synchronous methods. > >What I tried already, which I couldn't get to work, was to either fiddle >with things like `inspect` to see if the current function is async or to >use a class variable to indicate that the current class is the async >version. The idea was to write something like > >class MyAbstractType: >_use_async_calls = False >def foo(self): >x = self._await_if_i_am_async(self.bar) >y = self.baz(x) >... > >and that way, the async subclass just needs to change signatures to be >async with little stubs and set the flag, > >class AsyncConcreteType(MyAbstractType): >_use_async_calls = True >async def foo(self): >return super().foo() >async def bar(self): >return super().bar() As far as I understand (I am far from an `async` expert), `async` functions need to be specially compiled. This implies that there cannot be a runtime switch which makes a given function asynchronous or synchronous at runtime. You would need to have 2 functions, one asynchronous and one synchronous. Then a runtime switch may select the appropriate function. You likely can generate one of those function kinds from the other one by an `ast` (= "Abstract Syntax Tree") transformation. -- https://mail.python.org/mailman/listinfo/python-list
trying to improve my knn algorithm
This is a knn algorithm for articles that I have gotten. Then determines which
category it belongs to. I am not getting very good results :/
k = 23
training_folder = './data/training/'
minn_folder = training_folder + 'Minnesota/'
health_folder = training_folder + 'Health/'
def remove_punctuation(text):
return regex.sub(r'\p{P}+', "", text)
def file_list(folder):
return [f for f in listdir(folder) if isfile(join(folder, f))]
def all_file_list():
minn_files = file_list(minn_folder)
for i in range(len(minn_files)):
minn_files[i] = minn_folder + minn_files[i]
health_files = file_list(health_folder)
for i in range(len(health_files)):
health_files[i] = health_folder + health_files[i]
return minn_files + health_files
def file_to_word_list(f):
fr = open(f, 'r')
text_read = fr.read()
text = remove_punctuation(text_read)
return text.split()
def get_vocabularies(all_files):
voc = {}
for f in all_files:
words = file_to_word_list(f)
for w in words:
voc[w] = 0
return voc
def load_training_data():
all_files = all_file_list()
voc = get_vocabularies(all_files)
training_data = []
for f in all_files:
tag = f.split('/')[3]
point = copy.deepcopy(voc)
words = file_to_word_list(f)
for w in words:
point[w] += 1
d = {'tag': tag, 'point': point}
training_data.append(d)
return training_data
def get_distance(p1, p2):
sq_sum = 0
for w in p1:
if w in p2:
sq_sum += pow(p1[w] - p2[w], 2)
return math.sqrt(sq_sum)
# This function is implemented for seeing insights of training data
def show_distances(training_data):
for i in range(len(training_data)):
for j in range(i + 1, len(training_data)):
print('d(' + str(i) + ',' + str(j) + ')=')
print(get_distance(training_data[i]['point'],
training_data[j]['point']))
print()
for i in range(len(training_data)):
print(training_data[i]['tag'])
def test(training_data, txt_file):
dist_list = []
txt = {}
item = {}
max_i = 0
words = file_to_word_list(txt_file)
for w in words:
if w in txt:
txt[w] += 1
else:
txt[w] = 1
for pt in training_data:
item['tag'] = pt['tag']
item['distance'] = get_distance(pt['point'], txt)
if len(dist_list) < k:
dist_list.append(copy.deepcopy(item))
else:
for i in range(1, k):
if dist_list[i]['distance'] > dist_list[max_i]['distance']:
max_i = i
if dist_list[max_i]['distance'] > item['distance']:
dist_list[max_i] = item
vote_result = {}
for d in dist_list:
if d['tag'] in vote_result:
vote_result[d['tag']] += 1
else:
vote_result[d['tag']] = 1
# print(vote_result)# for testing
result = dist_list[0]['tag']
for vote in vote_result:
if vote_result[vote] > vote_result[result]:
result = vote
return result
def main(txt):
td = load_training_data()
print(show_distances(td))
# show_distances(td)# for test usage only
print('Category: ' + test(td, txt))
if __name__ == '__main__':
main(sys.argv[1])
--
https://mail.python.org/mailman/listinfo/python-list
Re: trying to improve my knn algorithm
[email protected] wrote: > This is a knn algorithm for articles that I have gotten. Then determines > which category it belongs to. I am not getting very good results :/ [snip too much code;)] - Shouldn't the word frequency vectors be normalized? I don't see that in your code. Without that the length of the text may overshade its contents. - There are probably words that are completely irrelevant. Getting rid of these should improve the signal-to-noise ratio. -- https://mail.python.org/mailman/listinfo/python-list
Re: trying to improve my knn algorithm
This is another account but I am the op. Why do you mean normalize? Sorry I’m new at this. -- https://mail.python.org/mailman/listinfo/python-list
