A simple LLM using Harbour's hashes
Posted: Tue May 16, 2023 6:03 am
An initial LLM ("large language model") using Harbour hashes:
llm.prg
llm.prg
- Code: Select all Expand view
- static hWords := {=>}
function Main()
AddSentence( hWords, hb_ATokens( "Hello my friend, Hello how are you ? Hello" ) )
? hWords[ "Hello" ][ 2 ][ "how" ]
return nil
function AddSentence( hWords, aWords )
local cWord
for each cWord in aWords
if ! hb_HHasKey( hWords, cWord )
hWords[ cWord ] = { 1, {=>} }
else
hWords[ cWord ][ 1 ]++
endif
AddSentence( hWords[ cWord ][ 2 ], SubArray( aWords, HB_EnumIndex() + 1 ) )
next
return nil
function SubArray( aArray, nStart )
local aSub := {}
for n = nStart to Len( aArray )
AAdd( aSub, aArray[ n ] )
next
return aSub