Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transition parsnip::set_model_args() inputs to main arguments #13

Merged
merged 2 commits into from
Nov 1, 2022
Merged

transition parsnip::set_model_args() inputs to main arguments #13

merged 2 commits into from
Nov 1, 2022

Conversation

simonpcouch
Copy link
Contributor

Hey there! Super stoked yall are putting this together.

Similar reprex to tidymodels/parsnip#832, with this PR:

library(tidybert)
library(tidymodels)
library(modeldata)
tidymodels_prefer()

data(tate_text)
tate_text <- tate_text %>%
  # We'll just work with the top 6 artists.
  dplyr::filter(
    artist %in% c(
      "Schütte, Thomas", "Zaatari, Akram", "Beuys, Joseph", "Ferrari, León",
      "Kossoff, Leon", "Tillmans, Wolfgang"
    )
  ) %>%
  dplyr::mutate(
    artist = as.factor(as.character(artist))
  )
set.seed(4242)
tate_folds <- rsample::vfold_cv(tate_text, v = 3)

tidybert_spec <-
  bert(
    mode = "classification",
    epochs = 1,
    bert_type = tune(),
    n_tokens = tune()
  ) %>%
  parsnip::set_engine(
    "tidybert"
  )

tidybert_workflow <- workflows::workflow(
  artist ~ title,
  tidybert_spec
)

grid <- tidybert_workflow %>%
  workflows::extract_parameter_set_dials() %>%
  update(
    bert_type = bert_type(
      c("bert_small_uncased", "bert_tiny_uncased")
    ),
    n_tokens = n_tokens(c(4, 5))
  ) %>%
  dials::grid_latin_hypercube(size = 2)

torch::torch_manual_seed(4242)
tidybert_result <- tidybert_workflow %>%
  tune::tune_grid(
    resamples = tate_folds,
    grid = grid
  )

tidybert_result
#> # Tuning results
#> # 3-fold cross-validation 
#> # A tibble: 3 × 4
#>   splits            id    .metrics         .notes          
#>   <list>            <chr> <list>           <list>          
#> 1 <split [405/203]> Fold1 <tibble [4 × 6]> <tibble [0 × 3]>
#> 2 <split [405/203]> Fold2 <tibble [4 × 6]> <tibble [0 × 3]>
#> 3 <split [406/202]> Fold3 <tibble [4 × 6]> <tibble [0 × 3]>

Created on 2022-10-28 with reprex v2.0.2

Some more details on this suggestion here. :)

@CLAassistant
Copy link

CLAassistant commented Oct 28, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@jonthegeek jonthegeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much! I'm merging this into a branch where I'm adding checks and vignette details around this, rather than into main, but this will be a huge help!

@jonthegeek jonthegeek changed the base branch from main to reparsnip November 1, 2022 15:57
@jonthegeek jonthegeek merged commit 276af40 into macmillancontentscience:reparsnip Nov 1, 2022
@simonpcouch simonpcouch deleted the model_args_832 branch November 1, 2022 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants