Skip to content

Commit

Permalink
committing updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
William-Yin123 committed Dec 28, 2019
1 parent 9d84621 commit 691b55f
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tensorflow/core/api_def/base_api/api_def_AsString.pbtxt
Expand Up @@ -42,5 +42,13 @@ Supports many numeric types and boolean.
For Unicode, see the
[https://www.tensorflow.org/tutorials/representation/unicode](Working with Unicode text)
tutorial.
Examples:
```python
>>> tf.strings.as_string([3.1415926, 2.71828])
<tf.Tensor: id=1, shape=(2,), dtype=string, numpy=array([b'3.141593', b'2.718280'], dtype=object)>
>>> tf.strings.as_string([3.1415926, 2.71828], precision=2)
<tf.Tensor: id=3, shape=(2,), dtype=string, numpy=array([b'3.14', b'2.72'], dtype=object)>
```
END
}
8 changes: 8 additions & 0 deletions tensorflow/core/api_def/base_api/api_def_RegexFullMatch.pbtxt
Expand Up @@ -26,5 +26,13 @@ The boolean values (True or False) of the output tensor indicate
if the input matches the regex pattern provided.
The pattern follows the re2 syntax (https://github.com/google/re2/wiki/Syntax)
Examples:
```python
>>> tf.strings.regex_full_match(["TensorFlow library", "Hello world"], ".*library$")
<tf.Tensor: id=322, shape=(2,), dtype=bool, numpy=array([ True, False])>
>>> tf.strings.regex_full_match(["TensorFlow library", "The library is called TensorFlow"], ".*library$")
<tf.Tensor: id=324, shape=(2,), dtype=bool, numpy=array([ True, False])>
```
END
}
7 changes: 7 additions & 0 deletions tensorflow/core/api_def/base_api/api_def_StringJoin.pbtxt
Expand Up @@ -17,5 +17,12 @@ END
summary: "Joins the strings in the given list of string tensors into one tensor;"
description: <<END
with the given separator (default is an empty separator).
Examples:
```python
>>> s = ["hello", "world", "tensorflow"]
>>> tf.strings.join(s, " ")
<tf.Tensor: id=11, shape=(), dtype=string, numpy=b'hello world tensorflow'>
```
END
}
8 changes: 8 additions & 0 deletions tensorflow/core/api_def/base_api/api_def_StringLower.pbtxt
@@ -1,3 +1,11 @@
op {
graph_op_name: "StringLower"
description: <<END
Examples:
```python
>>> tf.strings.lower(["HELLO", "TensorFlow"])
<tf.Tensor: id=369, shape=(2,), dtype=string, numpy=array([b'hello', b'tensorflow'], dtype=object)>
```
END
}
6 changes: 6 additions & 0 deletions tensorflow/core/api_def/base_api/api_def_StringStrip.pbtxt
Expand Up @@ -10,6 +10,12 @@ END
name: "output"
description: <<END
A string `Tensor` of the same shape as the input.
Examples:
```python
>>> tf.strings.strip(["\nTensorFlow", " The python library "])
<tf.Tensor: id=330, shape=(2,), dtype=string, numpy=array([b'TensorFlow', b'The python library'], dtype=object)>
```
END
}
summary: "Strip leading and trailing whitespaces from the Tensor."
Expand Down
Expand Up @@ -26,5 +26,11 @@ This function may be used when CPU time is scarce and inputs are trusted or
unimportant. There is a risk of adversaries constructing inputs that all hash
to the same bucket. To prevent this problem, use a strong hash function with
`tf.string_to_hash_bucket_strong`.
Examples:
```python
>>> tf.strings.to_hash_bucket_fast(["Hello", "TensorFlow", "2.x"], 3)
<tf.Tensor: id=334, shape=(3,), dtype=int64, numpy=array([0, 2, 2], dtype=int64)>
```
END
}
Expand Up @@ -40,5 +40,11 @@ seeded by a high-entropy (random) "key" unknown to the adversary.
The additional robustness comes at a cost of roughly 4x higher compute
time than `tf.string_to_hash_bucket_fast`.
Examples:
```python
>>> tf.strings.to_hash_bucket_strong(["Hello", "TensorFlow", "2.x"], 3, [1, 2])
<tf.Tensor: id=337, shape=(3,), dtype=int64, numpy=array([2, 2, 1], dtype=int64)>
```
END
}
8 changes: 8 additions & 0 deletions tensorflow/core/api_def/base_api/api_def_StringToNumber.pbtxt
Expand Up @@ -16,5 +16,13 @@ END
description: <<END
(Note that int32 overflow results in an error while float overflow
results in a rounded value.)
Examples:
```python
>>> tf.strings.to_number("1.55")
<tf.Tensor: id=345, shape=(), dtype=float32, numpy=1.55>
>>> tf.strings.to_number("3", tf.int32)
<tf.Tensor: id=347, shape=(), dtype=int32, numpy=3>
```
END
}
8 changes: 8 additions & 0 deletions tensorflow/core/api_def/base_api/api_def_StringUpper.pbtxt
@@ -1,3 +1,11 @@
op {
graph_op_name: "StringUpper"
description: <<END
Examples:
```python
>>> tf.strings.upper(["hello", "TensorFlow"])
<tf.Tensor: id=365, shape=(2,), dtype=string, numpy=array([b'HELLO', b'TENSORFLOW'], dtype=object)>
```
END
}
6 changes: 6 additions & 0 deletions tensorflow/core/api_def/base_api/api_def_UnicodeScript.pbtxt
Expand Up @@ -24,5 +24,11 @@ each code point. Script codes correspond to International Components for
Unicode (ICU) UScriptCode values. See http://icu-project.org/apiref/icu4c/uscript_8h.html.
Returns -1 (USCRIPT_INVALID_CODE) for invalid codepoints. Output shape will
match input shape.
Examples:
```python
>>> tf.strings.unicode_script([1, 31, 38])
<tf.Tensor: id=357, shape=(3,), dtype=int32, numpy=array([0, 0, 0])>
```
END
}
11 changes: 11 additions & 0 deletions tensorflow/core/api_def/base_api/api_def_UnicodeTranscode.pbtxt
Expand Up @@ -87,5 +87,16 @@ The end result is that if the input is marked as an explicit endianness the
transcoding is faithful to all codepoints in the source. If it is not marked
with an explicit endianness, the BOM is not considered part of the string itself
but as metadata, and so is not preserved in the output.
Examples:
```python
>>> tf.strings.unicode_transcode(["Hello", "TensorFlow", "2.x"], "UTF-8", "UTF-16-BE")
<tf.Tensor: id=359, shape=(3,), dtype=string, numpy=
array([b'\x00H\x00e\x00l\x00l\x00o',
b'\x00T\x00e\x00n\x00s\x00o\x00r\x00F\x00l\x00o\x00w',
b'\x002\x00.\x00x'], dtype=object)>
>>> tf.strings.unicode_transcode(["A", "B", "C"], "US ASCII", "UTF-8")
<tf.Tensor: id=363, shape=(3,), dtype=string, numpy=array([b'A', b'B', b'C'], dtype=object)>
```
END
}
9 changes: 9 additions & 0 deletions tensorflow/python/ops/ragged/ragged_string_ops.py
Expand Up @@ -679,6 +679,15 @@ def ngrams(data,
be prevented by setting `preserve_short_sequences`, which will cause the op
to always generate at least one ngram per non-empty sequence.
Examples:
```python
>>> tf.strings.ngrams(["TensorFlow", "and", "keras"], 2)
<tf.Tensor: id=285, shape=(2,), dtype=string, numpy=array([b'TensorFlow and', b'and keras'], dtype=object)>
>>> tf.strings.ngrams(["TensorFlow", "is", "a", "python", "library"], 3)
<tf.Tensor: id=320, shape=(3,), dtype=string, numpy=
array([b'TensorFlow is a', b'is a python', b'a python library'], dtype=object)>
```
Args:
data: A Tensor or RaggedTensor containing the source data for the ngrams.
ngram_width: The width(s) of the ngrams to create. If this is a list or
Expand Down
21 changes: 21 additions & 0 deletions tensorflow/python/ops/string_ops.py
Expand Up @@ -78,6 +78,13 @@ def regex_full_match(input, pattern, name=None):
def regex_replace(input, pattern, rewrite, replace_global=True, name=None):
r"""Replace elements of `input` matching regex `pattern` with `rewrite`.
Examples:
```python
>>> tf.strings.regex_replace(["python library", "python", "Python language"], "python", "TensorFlow")
<tf.Tensor: id=328, shape=(3,), dtype=string, numpy=
array([b'TensorFlow library', b'TensorFlow', b'Python language'], dtype=object)>
```
Args:
input: string `Tensor`, the source strings to process.
pattern: string or scalar string `Tensor`, regular expression to use,
Expand Down Expand Up @@ -470,6 +477,14 @@ def string_to_number(input, out_type=dtypes.float32, name=None):
(Note that int32 overflow results in an error while float overflow
results in a rounded value.)
Examples:
```python
>>> tf.strings.to_number("1.55")
<tf.Tensor: id=345, shape=(), dtype=float32, numpy=1.55>
>>> tf.strings.to_number("3", tf.int32)
<tf.Tensor: id=347, shape=(), dtype=int32, numpy=3>
```
Args:
input: A `Tensor` of type `string`.
out_type: An optional `tf.DType` from: `tf.float32, tf.float64, tf.int32,
Expand Down Expand Up @@ -509,6 +524,12 @@ def string_to_hash_bucket(input, num_buckets, name=None):
This functionality will be deprecated and it's recommended to use
`tf.strings.to_hash_bucket_fast()` or `tf.strings.to_hash_bucket_strong()`.
Examples:
```python
>>> tf.strings.to_hash_bucket(["Hello", "TensorFlow", "2.x"], 3)
<tf.Tensor: id=332, shape=(3,), dtype=int64, numpy=array([2, 0, 1], dtype=int64)>
```
Args:
input: A `Tensor` of type `string`.
num_buckets: An `int` that is `>= 1`. The number of buckets.
Expand Down

0 comments on commit 691b55f

Please sign in to comment.