From 4aec87365b6c119c8cb061a14d55f7da475af6ca Mon Sep 17 00:00:00 2001 From: PhasonMatrix Date: Sat, 20 Dec 2025 07:07:40 +1100 Subject: [PATCH 1/2] Fix: correct typos --- tutorials/CSharp/synthetic_data.ipynb | 10 +++++----- tutorials/CSharp/tutorial1.ipynb | 4 ++-- tutorials/CSharp/tutorial2.ipynb | 8 ++++---- tutorials/CSharp/tutorial3.ipynb | 2 +- tutorials/CSharp/tutorial4.ipynb | 2 +- tutorials/CSharp/tutorial5.ipynb | 6 +++--- tutorials/CSharp/tutorial6.ipynb | 20 ++++++++++---------- tutorials/CSharp/tutorial7.ipynb | 4 ++-- tutorials/FSharp/synthetic_data.ipynb | 10 +++++----- tutorials/FSharp/tutorial1.ipynb | 4 ++-- tutorials/FSharp/tutorial2.ipynb | 22 +++++++++++++++++++--- tutorials/FSharp/tutorial3.ipynb | 2 +- tutorials/FSharp/tutorial4.ipynb | 2 +- tutorials/FSharp/tutorial5.ipynb | 6 +++--- tutorials/FSharp/tutorial6.ipynb | 16 ++++++++-------- tutorials/FSharp/tutorial7.ipynb | 4 ++-- 16 files changed, 69 insertions(+), 53 deletions(-) diff --git a/tutorials/CSharp/synthetic_data.ipynb b/tutorials/CSharp/synthetic_data.ipynb index 73f5fed..5ad0677 100644 --- a/tutorials/CSharp/synthetic_data.ipynb +++ b/tutorials/CSharp/synthetic_data.ipynb @@ -11,7 +11,7 @@ "\n", "Synthetic data sets can be very useful when evaluating and choosing a model.\n", "\n", - "Note that we're taking some shortcuts in this example -- rather than writing the data set as a text file that can be loaded from any modeling framework, we're saving the data as serialized TorchSharp tensors. Is should be straight-forward to modify the tutorial to write the data sets as text, instead." + "Note that we're taking some shortcuts in this example -- rather than writing the data set as a text file that can be loaded from any modeling framework, we're saving the data as serialized TorchSharp tensors. It should be straight-forward to modify the tutorial to write the data sets as text, instead." ] }, { @@ -339,7 +339,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad();\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward();\n", "\n", " optimizer.step();\n", @@ -445,7 +445,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad();\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward();\n", "\n", " optimizer.step();\n", @@ -483,7 +483,7 @@ "source": [ "#### Dataset and DataLoader\n", "\n", - "If we wanted to be really advanced, we would use TorchSharp data sets and data loaders, which would allow us to randomize the test data set between epocs (at the end of the outer training loop). Here's how we'd do that." + "If we wanted to be really advanced, we would use TorchSharp data sets and data loaders, which would allow us to randomize the test data set between epochs (at the end of the outer training loop). Here's how we'd do that." ] }, { @@ -583,7 +583,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad();\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward();\n", "\n", " optimizer.step();\n", diff --git a/tutorials/CSharp/tutorial1.ipynb b/tutorials/CSharp/tutorial1.ipynb index 74010cf..a78da6f 100644 --- a/tutorials/CSharp/tutorial1.ipynb +++ b/tutorials/CSharp/tutorial1.ipynb @@ -83,7 +83,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "However, for these tutorials, it would obscure the API to have too many usings. It's better, for pedagocial reasons, to explicitly qualify names until their scope becomes well known. So, the tutorials will generally use a minimal set of usings." + "However, for these tutorials, it would obscure the API to have too many usings. It's better, for pedagogical reasons, to explicitly qualify names until their scope becomes well known. So, the tutorials will generally use a minimal set of usings." ] }, { @@ -128,7 +128,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Note that there are now three styles that may be used to format tensor output: C#-style, NumPy-style and Julia-style. The default is 'Julia,' but if you continue to use he top-of-notebook formatting, whatever you set it to in the cell at the top will be used to format tensors automatically." + "Note that there are now three styles that may be used to format tensor output: C#-style, NumPy-style and Julia-style. The default is 'Julia,' but if you continue to use the top-of-notebook formatting, whatever you set it to in the cell at the top will be used to format tensors automatically." ] }, { diff --git a/tutorials/CSharp/tutorial2.ipynb b/tutorials/CSharp/tutorial2.ipynb index 2b4119f..6a6d4d0 100644 --- a/tutorials/CSharp/tutorial2.ipynb +++ b/tutorials/CSharp/tutorial2.ipynb @@ -478,7 +478,7 @@ "\n", "### Extracting an Array from a Tensor\n", "\n", - "To get access to the internal data of a tensor as .NET array, use the 'data()' property. It doesn't return an array, but a TensorAccessor, which implements IEnumerable and can therefore be turned into an array. The TensorAccessor instance keeps a reference to the tensor data, but calling `ToArray()` on it will create a copy." + "To get access to the internal data of a tensor as a .NET array, use the 'data()' property. It doesn't return an array, but a TensorAccessor, which implements IEnumerable and can therefore be turned into an array. The TensorAccessor instance keeps a reference to the tensor data, but calling `ToArray()` on it will create a copy." ] }, { @@ -531,7 +531,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "As you can see, `arange` behaves a little differently from other factories -- the default element type is not float32, it's inferred from the arguments. To use floating-point, we an either specify the type, or use floating-point values as arguments:" + "As you can see, `arange` behaves a little differently from other factories -- the default element type is not float32, it's inferred from the arguments. To use floating-point, we can either specify the type, or use floating-point values as arguments:" ] }, { @@ -605,7 +605,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "When printing out floating-point tensors, it is often helpful to provide a formatting string, applied only to FP elements, including the real and imaginary parts of complex numbers. `.ToString(true, fltFormat: \"0.00\")` would be a lot to type every time, so TorcSharp defines a shorter (and Python-looking) method `str()` that does the trick. `print()` also takes a format string." + "When printing out floating-point tensors, it is often helpful to provide a formatting string, applied only to FP elements, including the real and imaginary parts of complex numbers. `.ToString(true, fltFormat: \"0.00\")` would be a lot to type every time, so TorchSharp defines a shorter (and Python-looking) method `str()` that does the trick. `print()` also takes a format string." ] }, { @@ -805,7 +805,7 @@ "source": [ "// On Apple HW (not x64), move to MPS and back:\n", "\n", - "// t.mps().cpu() // Uncomment if you're running on moder Apple HW." + "// t.mps().cpu() // Uncomment if you're running on modern Apple HW." ] }, { diff --git a/tutorials/CSharp/tutorial3.ipynb b/tutorials/CSharp/tutorial3.ipynb index e605f6c..77a0160 100644 --- a/tutorials/CSharp/tutorial3.ipynb +++ b/tutorials/CSharp/tutorial3.ipynb @@ -182,7 +182,7 @@ "source": [ "# Numerics Library\n", "\n", - "The collection of numerical operators that are available is too large to go through here, but suffice it to say that all the usual suspects are available. Most of the operate on an element-wise basis, i.e. the operator is applied to each element of the operands, possibly with broadcasting getting involved.\n", + "The collection of numerical operators that are available is too large to go through here, but suffice it to say that all the usual suspects are available. Most of them operate on an element-wise basis, i.e. the operator is applied to each element of the operands, possibly with broadcasting getting involved.\n", "\n", "One notable and __very__ significant exception is matrix multiplication, which is vector dot product generalized to matrices. The '*' operator denotes element-wise multiplication, while matrix multiplication is performed by the 'mm' method:" ] diff --git a/tutorials/CSharp/tutorial4.ipynb b/tutorials/CSharp/tutorial4.ipynb index 77a9ec2..06f6240 100644 --- a/tutorials/CSharp/tutorial4.ipynb +++ b/tutorials/CSharp/tutorial4.ipynb @@ -150,7 +150,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "To help with sampling, there's a class called `Binomial` whcih will run a number of coin tosses and count the number of times the result is '1'." + "To help with sampling, there's a class called `Binomial` which will run a number of coin tosses and count the number of times the result is '1'." ] }, { diff --git a/tutorials/CSharp/tutorial5.ipynb b/tutorials/CSharp/tutorial5.ipynb index 575d6e5..e415bbc 100644 --- a/tutorials/CSharp/tutorial5.ipynb +++ b/tutorials/CSharp/tutorial5.ipynb @@ -95,9 +95,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Copying a tensor from device to device is very straight-forward. Note that applying 'to()' to a tensor does not move it. Because of this inefficiency, it is better to create a tensor where it belongs, than to first create it on the CPU and move it over later. That said, it is often necessary to copy input data, because it comes from files and in-memory data that can only be turned into tensors on a CPU.\n", + "Copying a tensor from device to device is very straight-forward. Note that applying `to()` to a tensor does not move it. Because of this inefficiency, it is better to create a tensor where it belongs, than to first create it on the CPU and move it over later. That said, it is often necessary to copy input data, because it comes from files and in-memory data that can only be turned into tensors on a CPU.\n", "\n", - "There are two primary ways to copy a tensor to the GPU -- using 'cuda()' or using 'to()' The former is simpler, while the latter is more flexible -- it allows you to simultaneously convert the element type of a tensor and copy it over." + "There are two primary ways to copy a tensor to the GPU -- using `cuda()` or using `to()` The former is simpler, while the latter is more flexible -- it allows you to simultaneously convert the element type of a tensor and copy it over." ] }, { @@ -343,7 +343,7 @@ "source": [ "# Placing Model Parameters on the GPU\n", "\n", - "To use a GPU, tensors have to be copied or moved there. When you train, your data preparation logic is responsible for getting data to the GPU, but we also need the weights there. TorchSharp supports this by defining a 'to()' method on Modules, which can be used to move (not copy) the weights the model relies on to the GPU (or back to the CPU). We haven't looked at models yet, but keep this in mind for later:\n", + "To use a GPU, tensors have to be copied or moved there. When you train, your data preparation logic is responsible for getting data to the GPU, but we also need the weights there. TorchSharp supports this by defining a `to()` method on Modules, which can be used to move (not copy) the weights the model relies on to the GPU (or back to the CPU). We haven't looked at models yet, but keep this in mind for later:\n", "\n", "```C#\n", "var model = ...;\n", diff --git a/tutorials/CSharp/tutorial6.ipynb b/tutorials/CSharp/tutorial6.ipynb index a85b48f..7a02908 100644 --- a/tutorials/CSharp/tutorial6.ipynb +++ b/tutorials/CSharp/tutorial6.ipynb @@ -46,7 +46,7 @@ "source": [ "## Model Classes\n", "\n", - "Typically, we want to keep the logic of a model in a class of its own. This makes it easy to use other TorchSharp constructs to combine and run models. Conceptually, that's all a model is -- a Tensor -> Tensor function implemented as a class with a 'forward()' function. This function is where the logic of the model is placed. (If C# supported operator(), like C++ does, that's what we'd use here, instead. Just like Python does.)\n", + "Typically, we want to keep the logic of a model in a class of its own. This makes it easy to use other TorchSharp constructs to combine and run models. Conceptually, that's all a model is -- a Tensor -> Tensor function implemented as a class with a `forward()` function. This function is where the logic of the model is placed. (If C# supported `operator()`, like C++ does, that's what we'd use here, instead. Just like Python does.)\n", "\n", "TorchSharp makes it easy to build models, because you only have to specify the forward function. To do backprogation, you also need the backward function, which supports using the chain rule of calculus to calculate gradients. In Torch, the backward function is automatically implemented as long as the forward function relies only on Torch APIs for computations.\n", "\n", @@ -374,7 +374,7 @@ "// Clear the gradients before doing the back-propagation\n", "model.zero_grad();\n", "\n", - "// Do back-progatation, which computes all the gradients.\n", + "// Do back-propagation, which computes all the gradients.\n", "output.backward();\n", "\n", "// Adjust the weights using the gradients.\n", @@ -434,7 +434,7 @@ "// Clear the gradients before doing the back-propagation\n", "model.zero_grad();\n", "\n", - "// Do back-progatation, which computes all the gradients.\n", + "// Do back-propagation, which computes all the gradients.\n", "output.backward();\n", "\n", "optimizer.step();\n", @@ -477,7 +477,7 @@ "// Clear the gradients before doing the back-propagation\n", "model.zero_grad();\n", "\n", - "// Do back-progatation, which computes all the gradients.\n", + "// Do back-propagation, which computes all the gradients.\n", "output.backward();\n", "\n", "optimizer.step();\n", @@ -514,7 +514,7 @@ "// Clear the gradients before doing the back-propagation\n", "model.zero_grad();\n", "\n", - "// Do back-progatation, which computes all the gradients.\n", + "// Do back-propagation, which computes all the gradients.\n", "output.backward();\n", "\n", "optimizer.step();\n", @@ -555,7 +555,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad();\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward();\n", "\n", " optimizer.step();\n", @@ -870,7 +870,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Using Tensorbard\n", + "### Using Tensorboard\n", "\n", "Tensorboard is a tool that was originally built for Tensorflow, but it is general enough that it may be used with a number of data sources, including PyTorch and TorchSharp. The TorchSharp support for TB is limited, but it is useful for logging scalars during training, for example by logging accuracy or loss at the end of each epoch.\n", "\n", @@ -904,7 +904,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad();\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward();\n", "\n", " optimizer.step();\n", @@ -923,7 +923,7 @@ "source": [ "## Sequential\n", "\n", - "The prior sections have described the most general way of constructing a model, that is, by creating a class that abstracts the logic of the model and explicitly calls each layer's `forward` methos. While it's not too complicated to do so, it's a lot of \"ceremony\" to accomplish something very regular.\n", + "The prior sections have described the most general way of constructing a model, that is, by creating a class that abstracts the logic of the model and explicitly calls each layer's `forward` method. While it's not too complicated to do so, it's a lot of \"ceremony\" to accomplish something very regular.\n", "\n", "Fortunately, for models, or components of models, that simply pass one tensor from layer to layer, there's a class to handle it. It's called `Sequential` and is created by passing a sequence of tuples. The first element of the tuple is the name of the layer (required), and the second is the component.\n", "\n", @@ -954,7 +954,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "How can that be? Well, it's because save/load doesn't actually save and restore the model, it saves and restores the weights. All it cares about is that the layer's with weights have the same definition, and that they have the same name. In the Trivial case, the names were derived from the field names, and in the Sequential case, they are explicitly given. ReLU doesn't have any weights, so the fact that we did it differently doesn't factor it. The name of the relu layer can be anything, it just has to be something that isn't `null`.\n", + "How can that be? Well, it's because save/load doesn't actually save and restore the model, it saves and restores the weights. All it cares about is that the layers with weights have the same definition, and that they have the same name. In the Trivial case, the names were derived from the field names, and in the Sequential case, they are explicitly given. ReLU doesn't have any weights, so the fact that we did it differently doesn't factor it. The name of the relu layer can be anything, it just has to be something that isn't `null`.\n", "\n", "About `ReLU` -- in the Sequential case, we implemented that with a layer? That's because Sequential requires that its arguments be subclasses of `Module`, so a function doesn't work." ] diff --git a/tutorials/CSharp/tutorial7.ipynb b/tutorials/CSharp/tutorial7.ipynb index c7eb23a..32dbd7f 100644 --- a/tutorials/CSharp/tutorial7.ipynb +++ b/tutorials/CSharp/tutorial7.ipynb @@ -125,7 +125,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad();\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward();\n", "\n", " optimizer.step();\n", @@ -185,7 +185,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad();\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward();\n", "\n", " optimizer.step();\n", diff --git a/tutorials/FSharp/synthetic_data.ipynb b/tutorials/FSharp/synthetic_data.ipynb index 11be2ea..06fbddc 100644 --- a/tutorials/FSharp/synthetic_data.ipynb +++ b/tutorials/FSharp/synthetic_data.ipynb @@ -11,7 +11,7 @@ "\n", "Synthetic data sets can be very useful when evaluating and choosing a model.\n", "\n", - "Note that we're taking some shortcuts in this example -- rather than writing the data set as a text file that can be loaded from any modeling framework, we're saving the data as serialized TorchSharp tensors. Is should be straight-forward to modify the tutorial to write the data sets as text, instead." + "Note that we're taking some shortcuts in this example -- rather than writing the data set as a text file that can be loaded from any modeling framework, we're saving the data as serialized TorchSharp tensors. It should be straight-forward to modify the tutorial to write the data sets as text, instead." ] }, { @@ -315,7 +315,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad()\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward()\n", "\n", " optimizer.step() |> ignore\n", @@ -419,7 +419,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad()\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward()\n", "\n", " optimizer.step() |> ignore\n", @@ -455,7 +455,7 @@ "source": [ "#### Dataset and DataLoader\n", "\n", - "If we wanted to be really advanced, we would use TorchSharp data sets and data loaders, which would allow us to randomize the test data set between epocs (at the end of the outer training loop). Here's how we'd do that." + "If we wanted to be really advanced, we would use TorchSharp data sets and data loaders, which would allow us to randomize the test data set between epochs (at the end of the outer training loop). Here's how we'd do that." ] }, { @@ -545,7 +545,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad()\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward()\n", "\n", " optimizer.step() |> ignore\n", diff --git a/tutorials/FSharp/tutorial1.ipynb b/tutorials/FSharp/tutorial1.ipynb index 3a08983..9f13a7a 100644 --- a/tutorials/FSharp/tutorial1.ipynb +++ b/tutorials/FSharp/tutorial1.ipynb @@ -84,7 +84,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "However, for these tutorials, it would obscure the API to have too many `open` directives. It's better, for pedagocial reasons, to explicitly qualify names until their scope becomes well known. So, the tutorials will generally use a minimal set of `open` directives." + "However, for these tutorials, it would obscure the API to have too many `open` directives. It's better, for pedagogical reasons, to explicitly qualify names until their scope becomes well known. So, the tutorials will generally use a minimal set of `open` directives." ] }, { @@ -131,7 +131,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Note that there are now three styles that may be used to format tensor output: C#-style, NumPy-style and Julia-style. The default is 'Julia,' but if you continue to use he top-of-notebook formatting, whatever you set it to in the cell at the top will be used to format tensors automatically." + "Note that there are now three styles that may be used to format tensor output: C#-style, NumPy-style and Julia-style. The default is 'Julia,' but if you continue to use the top-of-notebook formatting, whatever you set it to in the cell at the top will be used to format tensors automatically." ] }, { diff --git a/tutorials/FSharp/tutorial2.ipynb b/tutorials/FSharp/tutorial2.ipynb index 34f9e79..6016021 100644 --- a/tutorials/FSharp/tutorial2.ipynb +++ b/tutorials/FSharp/tutorial2.ipynb @@ -439,7 +439,7 @@ "\n", "### Extracting an Array from a Tensor\n", "\n", - "To get access to the internal data of a tensor as .NET array, use the 'data()' property. It doesn't return an array, but a TensorAccessor, which implements IEnumerable and can therefore be turned into an array. The TensorAccessor instance keeps a reference to the tensor data, but calling `ToArray()` on it will create a copy." + "To get access to the internal data of a tensor as a .NET array, use the 'data()' property. It doesn't return an array, but a TensorAccessor, which implements IEnumerable and can therefore be turned into an array. The TensorAccessor instance keeps a reference to the tensor data, but calling `ToArray()` on it will create a copy." ] }, { @@ -492,7 +492,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "As you can see, `arange` behaves a little differently from other factories -- the default element type is not float32, it's inferred from the arguments. To use floating-point, we an either specify the type, or use floating-point values as arguments:" + "As you can see, `arange` behaves a little differently from other factories -- the default element type is not float32, it's inferred from the arguments. To use floating-point, we can either specify the type, or use floating-point values as arguments:" ] }, { @@ -566,7 +566,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "When printing out floating-point tensors, it is often helpful to provide a formatting string, applied only to FP elements, including the real and imaginary parts of complex numbers. `.ToString(true, fltFormat=\"0.00\")` would be a lot to type every time, so TorcSharp defines a shorter (and Python-looking) method `str()` that does the trick. `print()` also takes a format string." + "When printing out floating-point tensors, it is often helpful to provide a formatting string, applied only to FP elements, including the real and imaginary parts of complex numbers. `.ToString(true, fltFormat=\"0.00\")` would be a lot to type every time, so TorchSharp defines a shorter (and Python-looking) method `str()` that does the trick. `print()` also takes a format string." ] }, { @@ -748,6 +748,21 @@ "t.cpu()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "// On Apple HW (not x64), move to MPS and back:\n", + "\n", + "// t.mps().cpu() // Uncomment if you're running on modern Apple HW." + ] + }, { "cell_type": "code", "execution_count": null, @@ -761,6 +776,7 @@ }, "outputs": [], "source": [ + "// Getting the transpose of a matrix:\n", "torch.arange(3.0f, 5.0f, step=0.1f).reshape(4,5).print()\n", "torch.arange(3.0f, 5.0f, step=0.1f).reshape(4,5).T" ] diff --git a/tutorials/FSharp/tutorial3.ipynb b/tutorials/FSharp/tutorial3.ipynb index 332be48..2aef1c6 100644 --- a/tutorials/FSharp/tutorial3.ipynb +++ b/tutorials/FSharp/tutorial3.ipynb @@ -182,7 +182,7 @@ "source": [ "# Numerics Library\n", "\n", - "The collection of numerical operators that are available is too large to go through here, but suffice it to say that all the usual suspects are available. Most of the operate on an element-wise basis, i.e. the operator is applied to each element of the operands, possibly with broadcasting getting involved.\n", + "The collection of numerical operators that are available is too large to go through here, but suffice it to say that all the usual suspects are available. Most of them operate on an element-wise basis, i.e. the operator is applied to each element of the operands, possibly with broadcasting getting involved.\n", "\n", "One notable and __very__ significant exception is matrix multiplication, which is vector dot product generalized to matrices. The '*' operator denotes element-wise multiplication, while matrix multiplication is performed by the 'mm' method:" ] diff --git a/tutorials/FSharp/tutorial4.ipynb b/tutorials/FSharp/tutorial4.ipynb index 56900cb..fc0b3a4 100644 --- a/tutorials/FSharp/tutorial4.ipynb +++ b/tutorials/FSharp/tutorial4.ipynb @@ -151,7 +151,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "To help with sampling, there's a class called `Binomial` whcih will run a number of coin tosses and count the number of times the result is '1'." + "To help with sampling, there's a class called `Binomial` which will run a number of coin tosses and count the number of times the result is '1'." ] }, { diff --git a/tutorials/FSharp/tutorial5.ipynb b/tutorials/FSharp/tutorial5.ipynb index f912073..fa3c479 100644 --- a/tutorials/FSharp/tutorial5.ipynb +++ b/tutorials/FSharp/tutorial5.ipynb @@ -94,9 +94,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Copying a tensor from device to device is very straight-forward. Note that applying 'to()' to a tensor does not move it. Because of this inefficiency, it is better to create a tensor where it belongs, than to first create it on the CPU and move it over later. That said, it is often necessary to copy input data, because it comes from files and in-memory data that can only be turned into tensors on a CPU.\n", + "Copying a tensor from device to device is very straight-forward. Note that applying `to()` to a tensor does not move it. Because of this inefficiency, it is better to create a tensor where it belongs, than to first create it on the CPU and move it over later. That said, it is often necessary to copy input data, because it comes from files and in-memory data that can only be turned into tensors on a CPU.\n", "\n", - "There are two primary ways to copy a tensor to the GPU -- using 'cuda()' or using 'to()' The former is simpler, while the latter is more flexible -- it allows you to simultaneously convert the element type of a tensor and copy it over. Unfortunately, using 'to()' requires identifier escape in F#." + "There are two primary ways to copy a tensor to the GPU -- using `cuda()` or using `to()` The former is simpler, while the latter is more flexible -- it allows you to simultaneously convert the element type of a tensor and copy it over. Unfortunately, using `to()` requires identifier escape in F#." ] }, { @@ -362,7 +362,7 @@ "source": [ "# Placing Model Parameters on the GPU\n", "\n", - "To use a GPU, tensors have to be copied or moved there. When you train, your data preparation logic is responsible for getting data to the GPU, but we also need the weights there. TorchSharp supports this by defining a 'to()' method on Modules, which can be used to move (not copy) the weights the model relies on to the GPU (or back to the CPU). We haven't looked at models yet, but keep this in mind for later:\n", + "To use a GPU, tensors have to be copied or moved there. When you train, your data preparation logic is responsible for getting data to the GPU, but we also need the weights there. TorchSharp supports this by defining a `to()` method on Modules, which can be used to move (not copy) the weights the model relies on to the GPU (or back to the CPU). We haven't looked at models yet, but keep this in mind for later:\n", "\n", "```F#\n", "let model = ...\n", diff --git a/tutorials/FSharp/tutorial6.ipynb b/tutorials/FSharp/tutorial6.ipynb index 4bbb084..54ba0c9 100644 --- a/tutorials/FSharp/tutorial6.ipynb +++ b/tutorials/FSharp/tutorial6.ipynb @@ -46,7 +46,7 @@ "source": [ "## Model Classes\n", "\n", - "Typically, we want to keep the logic of a model in a class of its own. This makes it easy to use other TorchSharp constructs to combine and run models. Conceptually, that's all a model is -- a Tensor -> Tensor function implemented as a class with a 'forward()' function. This function is where the logic of the model is placed. (If C# supported operator(), like C++ does, that's what we'd use here, instead. Just like Python does.)\n", + "Typically, we want to keep the logic of a model in a class of its own. This makes it easy to use other TorchSharp constructs to combine and run models. Conceptually, that's all a model is -- a Tensor -> Tensor function implemented as a class with a `forward()` function. This function is where the logic of the model is placed. (If C# supported `operator()`, like C++ does, that's what we'd use here, instead. Just like Python does.)\n", "\n", "TorchSharp makes it easy to build models, because you only have to specify the forward function. To do backprogation, you also need the backward function, which supports using the chain rule of calculus to calculate gradients. In Torch, the backward function is automatically implemented as long as the forward function relies only on Torch APIs for computations.\n", "\n", @@ -362,7 +362,7 @@ "// Clear the gradients before doing the back-propagation\n", "model.zero_grad()\n", "\n", - "// Do back-progatation, which computes all the gradients.\n", + "// Do back-propagation, which computes all the gradients.\n", "output.backward()\n", "\n", "using(torch.no_grad()) (fun _ -> \n", @@ -421,7 +421,7 @@ "// Clear the gradients before doing the back-propagation\n", "model.zero_grad()\n", "\n", - "// Do back-progatation, which computes all the gradients.\n", + "// Do back-propagation, which computes all the gradients.\n", "output.backward()\n", "\n", "optimizer.step()\n", @@ -465,7 +465,7 @@ "// Clear the gradients before doing the back-propagation\n", "model.zero_grad()\n", "\n", - "// Do back-progatation, which computes all the gradients.\n", + "// Do back-propagation, which computes all the gradients.\n", "output.backward()\n", "\n", "optimizer.step()\n", @@ -505,7 +505,7 @@ "// Clear the gradients before doing the back-propagation\n", "model.zero_grad()\n", "\n", - "// Do back-progatation, which computes all the gradients.\n", + "// Do back-propagation, which computes all the gradients.\n", "output.backward()\n", "\n", "optimizer.step()\n", @@ -546,7 +546,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad()\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward()\n", "\n", " optimizer.step() |> ignore\n", @@ -812,7 +812,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad()\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward()\n", "\n", " optimizer.step() |> ignore\n", @@ -829,7 +829,7 @@ "source": [ "## Sequential\n", "\n", - "The prior sections have described the most general way of constructing a model, that is, by creating a class that abstracts the logic of the model and explicitly calls each layer's `forward` methos. While it's not too complicated to do so, it's a lot of \"ceremony\" to accomplish something very regular.\n", + "The prior sections have described the most general way of constructing a model, that is, by creating a class that abstracts the logic of the model and explicitly calls each layer's `forward` method. While it's not too complicated to do so, it's a lot of \"ceremony\" to accomplish something very regular.\n", "\n", "Fortunately, for models, or components of models, that simply pass one tensor from layer to layer, there's a class to handle it. It's called `Sequential` and is created by passing a sequence of modules." ] diff --git a/tutorials/FSharp/tutorial7.ipynb b/tutorials/FSharp/tutorial7.ipynb index 1396a94..3b66d35 100644 --- a/tutorials/FSharp/tutorial7.ipynb +++ b/tutorials/FSharp/tutorial7.ipynb @@ -121,7 +121,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad()\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward()\n", "\n", " optimizer.step() |> ignore\n", @@ -182,7 +182,7 @@ " // Clear the gradients before doing the back-propagation\n", " model.zero_grad()\n", "\n", - " // Do back-progatation, which computes all the gradients.\n", + " // Do back-propagation, which computes all the gradients.\n", " output.backward()\n", "\n", " optimizer.step() |> ignore\n", From 6e7aea20a67ed8d974d1b6cd082c24371d6b1439 Mon Sep 17 00:00:00 2001 From: PhasonMatrix Date: Sat, 20 Dec 2025 07:23:39 +1100 Subject: [PATCH 2/2] Fix: one more typo --- tutorials/FSharp/tutorial6.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/FSharp/tutorial6.ipynb b/tutorials/FSharp/tutorial6.ipynb index 54ba0c9..c0c63aa 100644 --- a/tutorials/FSharp/tutorial6.ipynb +++ b/tutorials/FSharp/tutorial6.ipynb @@ -778,7 +778,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Using Tensorbard\n", + "### Using Tensorboard\n", "\n", "Tensorboard is a tool that was originally built for Tensorflow, but it is general enough that it may be used with a number of data sources, including PyTorch and TorchSharp. The TorchSharp support for TB is limited, but it is useful for logging scalars during training, for example by logging accuracy or loss at the end of each epoch.\n", "\n",