Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,48 @@ on:
schedule:
- cron: 23 23 * * *
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
- name: Check if Julia is already available in the PATH
id: julia_in_path
run: which julia
continue-on-error: true
- name: Install Julia, but only if it is not already available in the PATH
uses: julia-actions/setup-julia@v2
with:
version: '1'
arch: ${{ runner.arch }}
if: steps.julia_in_path.outcome != 'success'
- name: "Add the General registry via Git"
run: |
import Pkg
ENV["JULIA_PKG_SERVER"] = ""
Pkg.Registry.add("General")
shell: julia --color=yes {0}
- name: "Install CompatHelper"
run: |
import Pkg
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
version = "3"
Pkg.add(; name, uuid, version)
shell: julia --color=yes {0}
- name: "Run CompatHelper"
run: |
import CompatHelper
CompatHelper.main()
shell: julia --color=yes {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# This repo uses Documenter, so we can reuse our [Documenter SSH key](https://documenter.juliadocs.org/stable/man/hosting/walkthrough/).
# If we didn't have one of those setup, we could configure a dedicated ssh deploy key `COMPATHELPER_PRIV` following https://juliaregistries.github.io/CompatHelper.jl/dev/#Creating-SSH-Key.
# Either way, we need an SSH key if we want the PRs that CompatHelper creates to be able to trigger CI workflows themselves.
# That is because GITHUB_TOKEN's can't trigger other workflows (see https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow).
# Check if you have a deploy key setup using these docs: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/reviewing-your-deploy-keys.
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
# COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }}
18 changes: 18 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ on:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: 3
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
Expand All @@ -12,3 +28,5 @@ jobs:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Edit the following line to reflect the actual name of the GitHub Secret containing your private key
ssh: ${{ secrets.DOCUMENTER_KEY }}
51 changes: 37 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,71 @@ jobs:
strategy:
matrix:
version:
- '1.6'
- 'nightly'
- '1.10'
- '1'
# - 'nightly' # incompatible due to strict world age semantics for global bindings in Julia 1.12.
os:
- ubuntu-latest
- macOS-latest
# - macOS-latest # DataDeps.download() issue
- windows-latest
arch:
- x86
# - x86
- x64
exclude:
# Remove some configurations from the build matrix to reduce CI time.
# See https://github.com/marketplace/actions/setup-julia-environment
# MacOS not available on x86
- {os: 'macOS-latest', arch: 'x86'}
# Don't test on all versions
- {os: 'macOS-latest', version: '1.6'}
- {os: 'macOS-latest', version: '1.10'}
- {os: 'macOS-latest', version: 'nightly'}
- {os: 'windows-latest', version: '1.6'}
- {os: 'windows-latest', version: '1.10'}
- {os: 'windows-latest', version: 'nightly'}
- {os: 'windows-latest', arch: 'x86'}
- {arch: 'x86', version: '1.6'}
- {arch: 'x86', version: '1.10'}
- {arch: 'x86', version: 'nightly'}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/cache@v2
- name: Install dependencies
run: |
if [[ "${{ matrix.version }}" == "1" || "${{ matrix.version }}" == "nightly" ]]; then
# Julia 1.11+ - Install dependencies without any precompilation
julia --project=. -e 'using Pkg; Pkg.instantiate(; allow_autoprecomp=false)'
else
# Julia 1.10 and earlier work normally
julia --project=. -e 'using Pkg; Pkg.instantiate()'
fi
env:
JULIA_CUDA_USE_BINARYBUILDER: false
JULIA_PKG_PRECOMPILE_AUTO: 0
shell: bash
- name: Run tests
run: |
if [[ "${{ matrix.version }}" == "1" || "${{ matrix.version }}" == "nightly" ]]; then
# Julia 1.11+ - Use minimal compilation and precompilation to avoid world age issues
julia --compiled-modules=no --pkgimages=no --color=yes --project=. -e 'using Pkg; Pkg.test()'
else
# Julia 1.10 and earlier can use normal compiled modules
julia --color=yes --project=. -e 'using Pkg; Pkg.test()'
fi
env:
DATADEPS_ALWAYS_ACCEPT: true
with:
coverage: false
JULIA_CUDA_USE_BINARYBUILDER: false
JULIA_PKG_PRECOMPILE_AUTO: 0
shell: bash
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: '1.6'
version: '1.11'
- run: julia --project=docs -e '
using Pkg;
Pkg.develop(PackageSpec(; path=pwd()));
Expand Down
26 changes: 14 additions & 12 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "TextModels"
uuid = "77b9cbda-2a23-51df-82a3-24144d1cd378"
license = "MIT"
desc = "Practical Neural Network based models for Natural Language Processing"
version = "0.1.1"
version = "0.2.0"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
Expand All @@ -12,6 +12,7 @@ DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Languages = "8ef0a80b-9436-5d2c-a485-80b904378c43"
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
Expand All @@ -24,19 +25,20 @@ WordTokenizers = "796a5d58-b03d-544a-977e-18100b691f6e"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[compat]
BSON = "0.3.3"
CUDA = "3"
BSON = "0.3"
CUDA = "3, 4, 5"
CorpusLoaders = "0.3"
DataDeps = "0.7"
DataStructures = "0.18.9"
Flux = "0.12.8"
JSON = "0.21.1"
Languages = "0.4.3"
NNlib = "0.7"
StatsBase = "0.33.6"
TextAnalysis = "0.7.3"
WordTokenizers = "0.5.6"
Zygote = "0.6.10"
DataStructures = "0.18, 0.19, 0.20"
Flux = "0.16, 0.17"
Functors = "0.4, 0.5, 0.6"
JSON = "0.21, 0.22"
Languages = "0.4"
NNlib = "0.7, 0.8, 0.9, 0.10"
StatsBase = "0.33, 0.34, 0.35"
TextAnalysis = "0.8"
WordTokenizers = "0.5, 0.6"
Zygote = "0.7, 0.8"
julia = "1.6"

[extras]
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ Contributions, in the form of bug-reports, pull requests, additional documentati

## Support

Feel free to ask for help on the [Julia Discourse forum](https://discourse.julialang.org/), or in the `#natural-language` channel on [julia-slack](https://julialang.slack.com). (Which you can [join here](https://slackinvite.julialang.org/)). You can also raise issues in this repository to request new features and/or improvements to the documentation and codebase.

Feel free to ask for help on the [Julia Discourse forum](https://discourse.julialang.org/), or in the `#natural-language` channel on [julia-slack](https://julialang.slack.com). (Which you can [join here](https://julialang.org/slack/)). Or, [select what do you like here](https://julialang.org/community/). You can also raise issues in this repository to request new features and/or improvements to the documentation and codebase.
2 changes: 1 addition & 1 deletion docs/src/crf.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This package currently provides support for Linear Chain Conditional Random Fiel
Let us first load the dependencies-

using Flux
using Flux: onehot, train!, Params, gradient, LSTM, Dense, reset!
using Flux: onehot, LSTM, Dense, reset!
using TextModels: CRF, viterbi_decode, crf_loss

Conditional Random Field layer is essentially like a softmax that operates on the top most layer.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/sentiment.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A StringDocument{String}
julia> m(d1)
0.5183109f0

julia> d = StringDocument("a horrible thing that everyone hates")
julia> d2 = StringDocument("a horrible thing that everyone hates")
A StringDocument{String}
* Language: Languages.English()
* Title: Untitled Document
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tagging.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The pretrained model can also be loaded and can be used directly to predict tags

### To train model:
```julia
julia> tagger = PerceptronTagger(false) #we can use tagger = PerceptronTagger()
julia> tagger = TextModels.PerceptronTagger(false) #we can use tagger = TextModels.PerceptronTagger()
julia> fit!(tagger, [[("today","NN"),("is","VBZ"),("good","JJ"),("day","NN")]])
iteration : 1
iteration : 2
Expand All @@ -47,7 +47,7 @@ iteration : 5

### To load pretrained model:
```julia
julia> tagger = PerceptronTagger(true)
julia> tagger = TextModels.PerceptronTagger(true)
loaded successfully
PerceptronTagger(AveragePerceptron(Set(Any["JJS", "NNP_VBZ", "NN_NNS", "CC", "NNP_NNS", "EX", "NNP_TO", "VBD_DT", "LS", ("Council", "NNP") … "NNPS", "NNP_LS", "VB", "NNS_NN", "NNP_SYM", "VBZ", "VBZ_JJ", "UH", "SYM", "NNP_NN", "CD"]), Dict{Any,Any}("i+2 word wetlands"=>Dict{Any,Any}("NNS"=>0.0,"JJ"=>0.0,"NN"=>0.0),"i-1 tag+i word NNP basic"=>Dict{Any,Any}("JJ"=>0.0,"IN"=>0.0),"i-1 tag+i word DT chloride"=>Dict{Any,Any}("JJ"=>0.0,"NN"=>0.0),"i-1 tag+i word NN choo"=>Dict{Any,Any}("NNP"=>0.0,"NN"=>0.0),"i+1 word antarctica"=>Dict{Any,Any}("FW"=>0.0,"NN"=>0.0),"i-1 tag+i word -START- appendix"=>Dict{Any,Any}("NNP"=>0.0,"NNPS"=>0.0,"NN"=>0.0),"i-1 word wahoo"=>Dict{Any,Any}("JJ"=>0.0,"VBD"=>0.0),"i-1 tag+i word DT children's"=>Dict{Any,Any}("NNS"=>0.0,"NN"=>0.0),"i word dnipropetrovsk"=>Dict{Any,Any}("NNP"=>0.003,"NN"=>-0.003),"i suffix hla"=>Dict{Any,Any}("JJ"=>0.0,"NN"=>0.0)…), DefaultDict{Any,Any,Int64}(), DefaultDict{Any,Any,Int64}(), 1, ["-START-", "-START2-"]), Dict{Any,Any}("is"=>"VBZ","at"=>"IN","a"=>"DT","and"=>"CC","for"=>"IN","by"=>"IN","Retrieved"=>"VBN","was"=>"VBD","He"=>"PRP","in"=>"IN"…), Set(Any["JJS", "NNP_VBZ", "NN_NNS", "CC", "NNP_NNS", "EX", "NNP_TO", "VBD_DT", "LS", ("Council", "NNP") … "NNPS", "NNP_LS", "VB", "NNS_NN", "NNP_SYM", "VBZ", "VBZ_JJ", "UH", "SYM", "NNP_NN", "CD"]), ["-START-", "-START2-"], ["-END-", "-END2-"], Any[])
```
Expand Down
3 changes: 2 additions & 1 deletion src/CRF/crf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function CRF(n::Integer)
return CRF(W, n)
end

@functor CRF
using Functors
Functors.@functor CRF

function Base.show(io::IO, c::CRF)
print(io, "CRF with ", c.n + 2, " distinct tags (including START and STOP tags).")
Expand Down
4 changes: 2 additions & 2 deletions src/CRF/loss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ thereby preventing operation.
eltype(label_seq) = Flux.OneHotVector
"""
function score_sequence(c::CRF, x, label_seq)
score = preds_first(c, label_seq[1]) + onecold(label_seq[1], x[1])
score = preds_first(c, label_seq[1]) + x[1][onecold(label_seq[1])]

for i in 2:length(label_seq)
score += preds_single(c, label_seq[i], label_seq[i-1]) +
onecold(label_seq[i], x[i])
x[i][onecold(label_seq[i])]
end

return score + preds_last(c, label_seq[end])
Expand Down
5 changes: 4 additions & 1 deletion src/TextModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module TextModels


using Flux, Zygote
using Flux: identity, onehot, onecold, @functor, onehotbatch
using Flux: identity, onehot, onecold, onehotbatch
using Functors


using TextAnalysis
Expand Down Expand Up @@ -47,13 +48,15 @@ module TextModels
using BSON
using CorpusLoaders
using DataDeps
using DelimitedFiles
include("ULMFiT/utils.jl")
include("ULMFiT/datadeps.jl")
include("ULMFiT/data_loaders.jl")
include("ULMFiT/custom_layers.jl")
include("ULMFiT/pretrain_lm.jl")
include("ULMFiT/fine_tune_lm.jl")
include("ULMFiT/train_text_classifier.jl")
include("ULMFiT/sentiment.jl")
end
export ULMFiT

Expand Down
Loading
Loading