Skip to content

Commit

Permalink
enable Momentum by default
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyongzhi committed Jan 19, 2021
1 parent ea43e10 commit f601894
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.vscode
*.cov
res/*/*
address_compare
guxiang_animation
address_compare*
guxiang_animation*
/*.png
test/*.jpg
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WordCloud"
uuid = "6385f0a0-cb03-45b6-9089-4e0acc74b26b"
authors = ["guoyongzhi <[email protected]>"]
version = "0.3.1"
version = "0.3.2"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ paint(wc, "alice.png", ratio=0.5, background=outline(wc.mask, color="purple", li
[Training animation](./examples/animation.jl)
*Run the command `runexample(:animation)` or `showexample(:animation)` to get the result.*
## Specifies the style of a particular word
![specifystyle](res/specifystyle.png)
[Specifies the style of a particular word](./examples/specifystyle.jl)
*Run the command `runexample(:specifystyle)` or `showexample(:specifystyle)` to get the result.*
![specifiedstyle](res/specifiedstyle.png)
[Specifies the style of a particular word](./examples/specifiedstyle.jl)
*Run the command `runexample(:specifiedstyle)` or `showexample(:specifiedstyle)` to get the result.*
## Comparison
![compare](res/compare.png)
[Comparison of Obama's and Trump's inaugural address](./examples/compare.jl)
Expand Down
2 changes: 1 addition & 1 deletion examples/alice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ wc = wordcloud(
colors = :Set1_5,
angles = (0, 90),
fillingrate = 0.7) |> generate!
println("save results to alice.png")
println("results are saved to alice.png")
paint(wc, "alice.png", background=outline(wc.mask, color="purple", linewidth=1))
wc
6 changes: 3 additions & 3 deletions examples/animation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ using DataFrames
using WordCloud

df = CSV.File(pkgdir(WordCloud)*"/res/guxiang_frequency.txt", header=false)|> DataFrame;
texts = df[!, "Column2"]
words = df[!, "Column2"]
weights = df[!, "Column3"]

wc = wordcloud(texts, weights, fillingrate=0.8)
println("save results to guxiang_animation")
wc = wordcloud(words, weights, fillingrate=0.8)
gifdirectory = "guxiang_animation"
generate_animation!(wc, 100, outputdir=gifdirectory)
println("results are saved in guxiang_animation")
wc
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/compare.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mb = paint(wcb)
h,w = size(ma)
space = fill(mb[1], (h, w÷20))
try mkdir("address_compare") catch end
println("save results to address_compare")
println("results are saved in address_compare")
WordCloud.ImageMagick.save("address_compare/compare.png", [ma space mb])

gif = WordCloud.GIF("address_compare")
Expand Down
4 changes: 2 additions & 2 deletions examples/specifystyle.jl → examples/specifiedstyle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ pin(wc, "Alice in Wonderland") do
generate!(wc)
end

println("save results to specifystyle.png")
paint(wc, "specifystyle.png")
println("results are saved to specifiedstyle.png")
paint(wc, "specifiedstyle.png")
wc
6 changes: 5 additions & 1 deletion src/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ function process(counter::Dict{<:AbstractString, <:Number};
maxnum=500,
minweight=1/maxnum, maxweight=minweight*20)
stopwords = Set(stopwords)
println("$(sum(values(counter))) words")
println("$(length(counter)) different words")
for (w, c) in counter
if (c < minfrequency || length(w) < minlength || length(w) > maxlength || lowercase(w) in stopwords)
if (c < minfrequency
|| length(w) < minlength || length(w) > maxlength
|| lowercase(w) in stopwords || w in stopwords)
delete!(counter, w)
end
end
Expand Down
1 change: 1 addition & 0 deletions src/rendering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ function try_gif_gen(gifdirectory; framerate=4)
-i $(gifdirectory)/result-palette.png -lavfi paletteuse -y $(gifdirectory)/result.gif`,
stdout=devnull, stderr=devnull) |> run
catch e
@warn "You need to have FFmpeg manually installed to use this function."
@warn e
end
end
Expand Down
5 changes: 3 additions & 2 deletions src/train.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ function teleport!(ts, maskqt, collpool, args...; kargs...)
end

function train!(ts, maskqt, nepoch::Number=-1, args...;
trainer=trainepoch_EM2!, patient::Number=trainer(:patient), callbackstep=0, callbackfun=x->x, kargs...)
trainer=trainepoch_EM2!, patient::Number=trainer(:patient), optimiser=Momentum=1/4, ρ=0.5),
callbackstep=0, callbackfun=x->x, kargs...)
ep = 0
nc = 0
count = 0
Expand All @@ -373,7 +374,7 @@ function train!(ts, maskqt, nepoch::Number=-1, args...;
@show nepoch, patient
while ep < nepoch
# @show "##", ep, nc, length(collpool), (count,nc_min)
nc = trainer(ts, maskqt, args...; resource..., kargs...)
nc = trainer(ts, maskqt, args...; resource..., optimiser=optimiser, kargs...)
ep += 1
count += 1
if nc < nc_min
Expand Down

0 comments on commit f601894

Please sign in to comment.