libcudf  23.12.00
subword_tokenize.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2023, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <cudf/column/column.hpp>
21 
22 namespace nvtext {
23 
34  uint16_t first_token_id{};
35  uint16_t separator_token_id{};
36  uint16_t unknown_token_id{};
37  uint32_t outer_hash_a{};
38  uint32_t outer_hash_b{};
39  uint16_t num_bins{};
40  std::unique_ptr<cudf::column> table;
42  std::unique_ptr<cudf::column> bin_coefficients;
44  std::unique_ptr<cudf::column> bin_offsets;
46  std::unique_ptr<cudf::column>
48  std::unique_ptr<cudf::column>
50 };
51 
66 std::unique_ptr<hashed_vocabulary> load_vocabulary_file(
67  std::string const& filename_hashed_vocabulary,
69 
77  uint32_t nrows_tensor{};
81  uint32_t sequence_length{};
88  std::unique_ptr<cudf::column> tensor_token_ids;
94  std::unique_ptr<cudf::column> tensor_attention_mask;
101  std::unique_ptr<cudf::column> tensor_metadata;
102 };
103 
152  cudf::strings_column_view const& strings,
153  hashed_vocabulary const& vocabulary_table,
154  uint32_t max_sequence_length,
155  uint32_t stride,
156  bool do_lower_case,
157  bool do_truncate,
159  // end of group
161 } // namespace nvtext
Given a column-view of strings type, an instance of this class provides a wrapper on this compound co...
Class definition for cudf::column.
column view class definitions
device_memory_resource * get_current_device_resource()
tokenizer_result subword_tokenize(cudf::strings_column_view const &strings, hashed_vocabulary const &vocabulary_table, uint32_t max_sequence_length, uint32_t stride, bool do_lower_case, bool do_truncate, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Creates a tokenizer that cleans the text, splits it into tokens and returns token-ids from an input v...
std::unique_ptr< hashed_vocabulary > load_vocabulary_file(std::string const &filename_hashed_vocabulary, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Load the hashed vocabulary file into device memory.
NVText APIs.
Class definition for cudf::strings_column_view.
The vocabulary data for use with the subword_tokenize function.
uint32_t outer_hash_a
The a parameter for the outer hash.
std::unique_ptr< cudf::column > bin_coefficients
uint32_t outer_hash_b
The b parameter for the outer hash.
std::unique_ptr< cudf::column > aux_cp_table
uint64 column, The auxiliary code point table to use for normalization
std::unique_ptr< cudf::column > bin_offsets
uint16_t separator_token_id
The separator token id in the vocabulary.
std::unique_ptr< cudf::column > table
std::unique_ptr< cudf::column > cp_metadata
uint32 column, The code point metadata table to use for normalization
uint16_t first_token_id
The first token id in the vocabulary.
uint16_t num_bins
Number of bins.
uint16_t unknown_token_id
The unknown token id in the vocabulary.
Result object for the subword_tokenize functions.
uint32_t sequence_length
The number of token-ids in each row.
uint32_t nrows_tensor
The number of rows for the output token-ids.
std::unique_ptr< cudf::column > tensor_token_ids
A vector of token-ids for each row.
std::unique_ptr< cudf::column > tensor_metadata
The metadata for each tensor row.
std::unique_ptr< cudf::column > tensor_attention_mask
This mask identifies which tensor-token-ids are valid.